diff --git a/pkg/pocketbase/src/plugin.ts b/pkg/pocketbase/src/plugin.ts index 6db66182..6fa73ac6 100644 --- a/pkg/pocketbase/src/plugin.ts +++ b/pkg/pocketbase/src/plugin.ts @@ -102,7 +102,7 @@ export const setupClient = p.new(['pb_address'], 'create pb_client', async (ctx) if (!(await isPbRunning())) return ctx.fail('Client is not running'); return ctx.pass('pb client successfully created'); } catch (e) { - return ctx.fail('Invalid address'); + throw new Error(e) } }); @@ -122,7 +122,7 @@ export const authWithPassword = p.new(['my_credentials'], 'login', async (ctx) = .authWithPassword(credentials!.email, credentials!.password, { requestKey: null }); return ctx.pass({ token: res.token, record: res.record }); } catch (err) { - return ctx.fail(err); + throw new Error(err) } }); @@ -169,7 +169,7 @@ export const showRecord = p.new(['show_parameters'], 'ask record', async (ctx) = const res = await pb.collection(p.collection).getOne(p.id, options); return ctx.pass(res); } catch (err) { - return ctx.fail(err); + throw new Error(err) } }); @@ -195,7 +195,7 @@ export const createRecord = p.new( const res = await pb.collection(collection).create(record, options); return ctx.pass(res); } catch (err) { - return ctx.fail(err.message); + throw new Error(err.message); } }, ); @@ -222,7 +222,7 @@ export const updateRecord = p.new( const res = await pb.collection(collection).update(id, record, options); return ctx.pass(res); } catch (err) { - return ctx.fail(err.message); + throw new Error(err.message); } }, ); diff --git a/pkg/pocketbase/test/e2e.ts b/pkg/pocketbase/test/e2e.ts index d89cccc2..f7b99426 100644 --- a/pkg/pocketbase/test/e2e.ts +++ b/pkg/pocketbase/test/e2e.ts @@ -11,11 +11,10 @@ import type { import { pocketbase } from '@slangroom/pocketbase'; import test from 'ava'; import { Slangroom } from '@slangroom/core'; -import 'dotenv/config'; -const email = process.env['EMAIL']!; -const password = process.env['PASSWORD']!; -const pb_address = process.env['PB_ADDRESS']! as ServerUrl; +const email = "test@test.eu"; +const password = "testtest"; +const pb_address = "http://127.0.0.1:8090/" as ServerUrl; type DataCreate = { create_parameters: CreateRecordParameters; @@ -123,11 +122,11 @@ test('should retrieve paginated list of records', async (t) => { data, }); const output = res.result['output'] as { - records?: { items?: []; page?: number; perPage?: number }; + records?: { items?: []; page?: string; perPage?: string}; }; t.truthy(Array.isArray(output.records?.items)); - t.is(output.records?.page, 2); - t.is(output.records?.perPage, 20); + t.is(output.records?.page, '2'); + t.is(output.records?.perPage, '20'); }); test('should retrieve first record that match filters', async (t) => { @@ -172,7 +171,7 @@ test('should retrieve one record', async (t) => { pb_address, show_parameters: { collection: 'organizations', - id: 'ouja6pwgxuyn2sd', + id: 'p7viyzsihrn52uj', fields: 'name', requestKey: null, expand:null @@ -199,14 +198,14 @@ test('should create a record', async (t) => { `; const slangroom = new Slangroom(pocketbase); - + const data: DataCreate = { pb_address, create_parameters: { collection: 'organizations', record: { name, - }, + }, }, record_parameters: { expand: null, @@ -226,7 +225,7 @@ test('should create a record', async (t) => { }); test('should update a record', async (t) => { - + const scriptCreate = ` Rule unknown ignore @@ -280,7 +279,7 @@ test('should update a record', async (t) => { const outputCreate = createResult.result['output'] as { id: string, name: string} const updatedName = `test-${randomString()}` - + const dataUpdate: DataUpdate = { pb_address, update_parameters: { diff --git a/pkg/pocketbase/test/pb_data/data.db b/pkg/pocketbase/test/pb_data/data.db new file mode 100644 index 00000000..3ddf4728 Binary files /dev/null and b/pkg/pocketbase/test/pb_data/data.db differ diff --git a/pkg/pocketbase/test/pb_migrations/1708946882_created_organizations.js b/pkg/pocketbase/test/pb_migrations/1708946882_created_organizations.js new file mode 100644 index 00000000..48b03b81 --- /dev/null +++ b/pkg/pocketbase/test/pb_migrations/1708946882_created_organizations.js @@ -0,0 +1,85 @@ +/// +migrate((db) => { + const collection = new Collection({ + "id": "ffzsqtnsh1w2ayd", + "created": "2024-02-26 11:28:02.724Z", + "updated": "2024-02-26 11:28:02.724Z", + "name": "organizations", + "type": "base", + "system": false, + "schema": [ + { + "system": false, + "id": "a9jbay3n", + "name": "name", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "z1xvmjl0", + "name": "owners", + "type": "relation", + "required": false, + "presentable": false, + "unique": false, + "options": { + "collectionId": "_pb_users_auth_", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": null + } + }, + { + "system": false, + "id": "cy2pwsn3", + "name": "avatar", + "type": "file", + "required": false, + "presentable": false, + "unique": false, + "options": { + "mimeTypes": [], + "thumbs": [], + "maxSelect": 1, + "maxSize": 5242880, + "protected": false + } + }, + { + "system": false, + "id": "u6ro0mgl", + "name": "description", + "type": "editor", + "required": false, + "presentable": false, + "unique": false, + "options": { + "convertUrls": false + } + } + ], + "indexes": [], + "listRule": null, + "viewRule": null, + "createRule": null, + "updateRule": null, + "deleteRule": null, + "options": {} + }); + + return Dao(db).saveCollection(collection); +}, (db) => { + const dao = new Dao(db); + const collection = dao.findCollectionByNameOrId("ffzsqtnsh1w2ayd"); + + return dao.deleteCollection(collection); +}) diff --git a/pkg/pocketbase/test/pocketbase b/pkg/pocketbase/test/pocketbase new file mode 100755 index 00000000..f3738529 Binary files /dev/null and b/pkg/pocketbase/test/pocketbase differ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 48cb41c5..abc4e90b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -113,7 +113,7 @@ importers: version: 1.6.2 web3: specifier: ^4.3.0 - version: 4.3.0(typescript@5.2.2) + version: 4.3.0(typescript@5.3.3) web3-validator: specifier: ^2.0.3 version: 2.0.3 @@ -202,8 +202,8 @@ importers: specifier: ^16.3.1 version: 16.3.1 pocketbase: - specifier: ^0.19.0 - version: 0.19.0 + specifier: ^0.21.1 + version: 0.21.1 zod: specifier: ^3.22.4 version: 3.22.4 @@ -1687,7 +1687,7 @@ packages: engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} dev: true - /abitype@0.7.1(typescript@5.2.2): + /abitype@0.7.1(typescript@5.3.3): resolution: {integrity: sha512-VBkRHTDZf9Myaek/dO3yMmOzB/y2s3Zo6nVU7yaw1G+TvCHAjwaJzNGN9yo4K5D8bU/VZXKP1EJpRhFr862PlQ==} peerDependencies: typescript: '>=4.9.4' @@ -1696,7 +1696,7 @@ packages: zod: optional: true dependencies: - typescript: 5.2.2 + typescript: 5.3.3 dev: false /abort-controller@3.0.0: @@ -4937,8 +4937,8 @@ packages: engines: {node: '>=10.13.0'} dev: false - /pocketbase@0.19.0: - resolution: {integrity: sha512-bUVZfVdD17K8GnwbeDMZPEdREVg2YE0F8uHPDC0zer4VtwXUqoPCCeudTy3fhUE7pfuKnfpuPxeBSYsBY3AGIQ==} + /pocketbase@0.21.1: + resolution: {integrity: sha512-0PvCP4pKtxsV9kwldEGyibEvhwOcx9jSCrz3WN5CgPILJfM0z76f1op9WE8/8UgikDsMdRsc5iBLfKintrJS1g==} dev: false /postcss-selector-parser@6.0.13: @@ -5809,6 +5809,13 @@ packages: resolution: {integrity: sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==} engines: {node: '>=14.17'} hasBin: true + dev: true + + /typescript@5.3.3: + resolution: {integrity: sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==} + engines: {node: '>=14.17'} + hasBin: true + dev: false /uglify-js@3.17.4: resolution: {integrity: sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==} @@ -5944,11 +5951,11 @@ packages: web3-types: 1.3.1 dev: false - /web3-eth-abi@4.1.4(typescript@5.2.2): + /web3-eth-abi@4.1.4(typescript@5.3.3): resolution: {integrity: sha512-YLOBVVxxxLYKXjaiwZjEWYEnkMmmrm0nswZsvzSsINy/UgbWbzfoiZU+zn4YNWIEhORhx1p37iS3u/dP6VyC2w==} engines: {node: '>=14', npm: '>=6.12.0'} dependencies: - abitype: 0.7.1(typescript@5.2.2) + abitype: 0.7.1(typescript@5.3.3) web3-errors: 1.1.4 web3-types: 1.3.1 web3-utils: 4.1.0 @@ -5971,14 +5978,14 @@ packages: web3-validator: 2.0.3 dev: false - /web3-eth-contract@4.1.4(typescript@5.2.2): + /web3-eth-contract@4.1.4(typescript@5.3.3): resolution: {integrity: sha512-tJ4z6QLgtu8EQu2sXnLA7g427oxmngnbAUh+9kJKbP6Yep/oe+z79PqJv7H3MwqwUNW9T+/FeB2PnSQSyxz6ig==} engines: {node: '>=14', npm: '>=6.12.0'} dependencies: web3-core: 4.3.2 web3-errors: 1.1.4 - web3-eth: 4.3.1(typescript@5.2.2) - web3-eth-abi: 4.1.4(typescript@5.2.2) + web3-eth: 4.3.1(typescript@5.3.3) + web3-eth-abi: 4.1.4(typescript@5.3.3) web3-types: 1.3.1 web3-utils: 4.1.0 web3-validator: 2.0.3 @@ -5990,15 +5997,15 @@ packages: - zod dev: false - /web3-eth-ens@4.0.8(typescript@5.2.2): + /web3-eth-ens@4.0.8(typescript@5.3.3): resolution: {integrity: sha512-nj0JfeD45BbzVJcVYpUJnSo8iwDcY9CQ7CZhhIVVOFjvpMAPw0zEwjTvZEIQyCW61OoDG9xcBzwxe2tZoYhMRw==} engines: {node: '>=14', npm: '>=6.12.0'} dependencies: '@adraffy/ens-normalize': 1.10.0 web3-core: 4.3.2 web3-errors: 1.1.4 - web3-eth: 4.3.1(typescript@5.2.2) - web3-eth-contract: 4.1.4(typescript@5.2.2) + web3-eth: 4.3.1(typescript@5.3.3) + web3-eth-contract: 4.1.4(typescript@5.3.3) web3-net: 4.0.7 web3-types: 1.3.1 web3-utils: 4.1.0 @@ -6021,12 +6028,12 @@ packages: web3-validator: 2.0.3 dev: false - /web3-eth-personal@4.0.8(typescript@5.2.2): + /web3-eth-personal@4.0.8(typescript@5.3.3): resolution: {integrity: sha512-sXeyLKJ7ddQdMxz1BZkAwImjqh7OmKxhXoBNF3isDmD4QDpMIwv/t237S3q4Z0sZQamPa/pHebJRWVuvP8jZdw==} engines: {node: '>=14', npm: '>=6.12.0'} dependencies: web3-core: 4.3.2 - web3-eth: 4.3.1(typescript@5.2.2) + web3-eth: 4.3.1(typescript@5.3.3) web3-rpc-methods: 1.1.4 web3-types: 1.3.1 web3-utils: 4.1.0 @@ -6039,14 +6046,14 @@ packages: - zod dev: false - /web3-eth@4.3.1(typescript@5.2.2): + /web3-eth@4.3.1(typescript@5.3.3): resolution: {integrity: sha512-zJir3GOXooHQT85JB8SrufE+Voo5TtXdjhf1D8IGXmxM8MrhI8AT+Pgt4siBTupJcu5hF17iGmTP/Nj2XnaibQ==} engines: {node: '>=14', npm: '>=6.12.0'} dependencies: setimmediate: 1.0.5 web3-core: 4.3.2 web3-errors: 1.1.4 - web3-eth-abi: 4.1.4(typescript@5.2.2) + web3-eth-abi: 4.1.4(typescript@5.3.3) web3-eth-accounts: 4.1.0 web3-net: 4.0.7 web3-providers-ws: 4.0.7 @@ -6153,19 +6160,19 @@ packages: zod: 3.22.4 dev: false - /web3@4.3.0(typescript@5.2.2): + /web3@4.3.0(typescript@5.3.3): resolution: {integrity: sha512-YiLCsb5wmgJlSxRLzt7Z7H+CmlVVIKD8VaUQaZ+xKVG3Q7CpsO5Z6jmeKnlr6M9c6fDDsDnRM6G8g+nchZehbA==} engines: {node: '>=14.0.0', npm: '>=6.12.0'} dependencies: web3-core: 4.3.2 web3-errors: 1.1.4 - web3-eth: 4.3.1(typescript@5.2.2) - web3-eth-abi: 4.1.4(typescript@5.2.2) + web3-eth: 4.3.1(typescript@5.3.3) + web3-eth-abi: 4.1.4(typescript@5.3.3) web3-eth-accounts: 4.1.0 - web3-eth-contract: 4.1.4(typescript@5.2.2) - web3-eth-ens: 4.0.8(typescript@5.2.2) + web3-eth-contract: 4.1.4(typescript@5.3.3) + web3-eth-ens: 4.0.8(typescript@5.3.3) web3-eth-iban: 4.0.7 - web3-eth-personal: 4.0.8(typescript@5.2.2) + web3-eth-personal: 4.0.8(typescript@5.3.3) web3-net: 4.0.7 web3-providers-http: 4.1.0 web3-providers-ws: 4.0.7