UNPKG

@deep-foundation/deeplinks

Version:

[![npm](https://img.shields.io/npm/v/@deep-foundation/deeplinks.svg)](https://www.npmjs.com/package/@deep-foundation/deeplinks) [![Gitpod](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/deep-fo

496 lines 258 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; import { assert, expect } from 'chai'; import { generateApolloClient } from '@deep-foundation/hasura/client.js'; import { DeepClient } from "../imports/client"; import { insertHandler, insertSelector, insertSelectorItem, deleteHandler, deleteSelector } from "../imports/handlers"; import { HasuraApi } from '@deep-foundation/hasura/api'; import { sql } from '@deep-foundation/hasura/sql.js'; import { _ids } from '../imports/client.js'; import Debug from 'debug'; import { serializeError } from 'serialize-error'; const debug = Debug('deeplinks:tests:sync-handlers'); const log = debug.extend('log'); const error = debug.extend('error'); const delay = time => new Promise(res => setTimeout(res, time)); const HASURA_PATH = 'localhost:8080'; const HASURA_SSL = 0; const HASURA_SECRET = 'myadminsecretkey'; export const api = new HasuraApi({ path: HASURA_PATH, ssl: !!+HASURA_SSL, secret: HASURA_SECRET, }); const apolloClient = generateApolloClient({ path: `${process.env.DEEPLINKS_HASURA_PATH}/v1/graphql`, ssl: !!+process.env.DEEPLINKS_HASURA_SSL, secret: process.env.DEEPLINKS_HASURA_SECRET, }); const deep = new DeepClient({ apolloClient }); const handleInsertTypeId = (_a = _ids === null || _ids === void 0 ? void 0 : _ids['@deep-foundation/core']) === null || _a === void 0 ? void 0 : _a.HandleInsert; const handleUpdateTypeId = (_b = _ids === null || _ids === void 0 ? void 0 : _ids['@deep-foundation/core']) === null || _b === void 0 ? void 0 : _b.HandleUpdate; const handleDeleteTypeId = (_c = _ids === null || _ids === void 0 ? void 0 : _ids['@deep-foundation/core']) === null || _c === void 0 ? void 0 : _c.HandleDelete; ; const userTypeId = (_d = _ids === null || _ids === void 0 ? void 0 : _ids['@deep-foundation/core']) === null || _d === void 0 ? void 0 : _d.User; const packageTypeId = (_e = _ids === null || _ids === void 0 ? void 0 : _ids['@deep-foundation/core']) === null || _e === void 0 ? void 0 : _e.Package; const containTypeId = (_f = _ids === null || _ids === void 0 ? void 0 : _ids['@deep-foundation/core']) === null || _f === void 0 ? void 0 : _f.Contain; const plv8SupportsJsTypeId = (_g = _ids === null || _ids === void 0 ? void 0 : _ids['@deep-foundation/core']) === null || _g === void 0 ? void 0 : _g.plv8SupportsJs; const HandlerTypeId = (_h = _ids === null || _ids === void 0 ? void 0 : _ids['@deep-foundation/core']) === null || _h === void 0 ? void 0 : _h.Handler; const SelectorTypeId = (_j = _ids === null || _ids === void 0 ? void 0 : _ids['@deep-foundation/core']) === null || _j === void 0 ? void 0 : _j.Selector; const AllowSelectTypeId = (_k = _ids === null || _ids === void 0 ? void 0 : _ids['@deep-foundation/core']) === null || _k === void 0 ? void 0 : _k.AllowSelectType; const AllowSelectId = (_l = _ids === null || _ids === void 0 ? void 0 : _ids['@deep-foundation/core']) === null || _l === void 0 ? void 0 : _l.AllowSelect; const AllowAdminId = (_m = _ids === null || _ids === void 0 ? void 0 : _ids['@deep-foundation/core']) === null || _m === void 0 ? void 0 : _m.AllowAdmin; log({ handleInsertTypeId, handleUpdateTypeId, handleDeleteTypeId, userTypeId, packageTypeId, containTypeId, plv8SupportsJsTypeId, HandlerTypeId, SelectorTypeId, AllowSelectTypeId, AllowSelectId, AllowAdminId }); describe('sync handlers', () => { describe('Prepare fuction', () => { it(`handleInsert`, () => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c; const handlerId = deep.idLocal('@deep-foundation/core', 'HandleInsert'); const link = JSON.stringify({ id: 1, type_id: 1 }); const result = yield api.sql(sql `select links__sync__handlers__prepare__function('${link}'::jsonb, ${handlerId}::bigint)`); log('prepare result', (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c[0]); })); }); describe('DeepClient mini', () => { it(`id`, () => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g; const result = yield api.sql(sql `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'id', '["@deep-foundation/core", "Rule"]'::jsonb, '{}'::jsonb)`); const clientResult = deep.idLocal('@deep-foundation/core', 'Rule'); log('id result', (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c[0]); assert.equal((_g = JSON.parse((_f = (_e = (_d = result === null || result === void 0 ? void 0 : result.data) === null || _d === void 0 ? void 0 : _d.result) === null || _e === void 0 ? void 0 : _e[1]) === null || _f === void 0 ? void 0 : _f[0])) === null || _g === void 0 ? void 0 : _g[0], clientResult); })); it(`login as guest and insert`, () => __awaiter(void 0, void 0, void 0, function* () { var _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v; const debug = log.extend('HandleInsert'); const guest = yield deep.guest({}); const typeId = deep.idLocal('@deep-foundation/core', 'Operation'); const handleInsertTypeId = deep.idLocal('@deep-foundation/core', 'HandleInsert'); const supportsId = deep.idLocal('@deep-foundation/core', 'plv8SupportsJs'); const anyTypeId = deep.idLocal('@deep-foundation/core', 'Any'); const inserted = yield deep.insert({ type_id: 1, from_id: anyTypeId, to_id: anyTypeId }); const customLinkId = (_j = (_h = inserted === null || inserted === void 0 ? void 0 : inserted.data) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.id; debug('customLinkId', customLinkId); const handler = yield insertHandler(handleInsertTypeId, typeId, `({deep, data}) => { const initId = deep.linkId; deep.login({linkId:${guest.linkId}}); deep.insert({type_id: ${customLinkId}, to_id: ${customLinkId}, from_id: ${customLinkId}, object: { initId, guestId: deep.linkId }}); }`, undefined, supportsId); debug('handler', handler); try { const linkId = (_l = (_k = (yield deep.insert({ type_id: typeId }))) === null || _k === void 0 ? void 0 : _k.data) === null || _l === void 0 ? void 0 : _l[0].id; debug('linkId', linkId); debug('delete linkid', yield deep.delete({ id: { _eq: linkId } })); } catch (e) { const serializedError = serializeError(e); debug('insert error: ', JSON.stringify(serializedError, null, 2)); } const insertedByHandler = yield deep.select({ type_id: { _eq: customLinkId }, to_id: { _eq: customLinkId }, from_id: { _eq: customLinkId } }); debug('adminId', yield deep.id('deep', 'admin')); debug('insertedByHandler', insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data); debug('insertedByHandler data', (_p = (_o = (_m = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _m === void 0 ? void 0 : _m[0]) === null || _o === void 0 ? void 0 : _o.value) === null || _p === void 0 ? void 0 : _p.value); if ((_r = (_q = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _q === void 0 ? void 0 : _q[0]) === null || _r === void 0 ? void 0 : _r.id) yield deep.delete((_t = (_s = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _s === void 0 ? void 0 : _s[0]) === null || _t === void 0 ? void 0 : _t.id); yield deep.delete(customLinkId); debug('delete handler', yield deleteHandler(handler)); assert.equal(!!((_v = (_u = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _u === void 0 ? void 0 : _u[0]) === null || _v === void 0 ? void 0 : _v.id), false); })); it(`login as guest, relogin as admin and insert`, () => __awaiter(void 0, void 0, void 0, function* () { var _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8; const debug = log.extend('HandleInsert'); const guest = yield deep.guest({}); const typeId = deep.idLocal('@deep-foundation/core', 'Operation'); const handleInsertTypeId = deep.idLocal('@deep-foundation/core', 'HandleInsert'); const supportsId = deep.idLocal('@deep-foundation/core', 'plv8SupportsJs'); const anyTypeId = deep.idLocal('@deep-foundation/core', 'Any'); const inserted = yield deep.insert({ type_id: 1, from_id: anyTypeId, to_id: anyTypeId }); const customLinkId = (_x = (_w = inserted === null || inserted === void 0 ? void 0 : inserted.data) === null || _w === void 0 ? void 0 : _w[0]) === null || _x === void 0 ? void 0 : _x.id; debug('customLinkId', customLinkId); const handler = yield insertHandler(handleInsertTypeId, typeId, `({deep, data}) => { deep.login({linkId:${yield deep.id('deep', 'admin')}}); deep.insert({type_id: ${customLinkId}, to_id: ${customLinkId}, from_id: ${customLinkId}}); }`, undefined, supportsId); debug('handler', handler); try { const linkId = (_z = (_y = (yield deep.insert({ type_id: typeId }))) === null || _y === void 0 ? void 0 : _y.data) === null || _z === void 0 ? void 0 : _z[0].id; debug('linkId', linkId); debug('delete linkid', yield deep.delete({ id: { _eq: linkId } })); } catch (e) { const serializedError = serializeError(e); debug('insert error: ', JSON.stringify(serializedError, null, 2)); } const insertedByHandler = yield deep.select({ type_id: { _eq: customLinkId }, to_id: { _eq: customLinkId }, from_id: { _eq: customLinkId } }); debug('adminId', yield deep.id('deep', 'admin')); debug('insertedByHandler', insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data); debug('insertedByHandler data', (_2 = (_1 = (_0 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _0 === void 0 ? void 0 : _0[0]) === null || _1 === void 0 ? void 0 : _1.value) === null || _2 === void 0 ? void 0 : _2.value); if ((_4 = (_3 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _3 === void 0 ? void 0 : _3[0]) === null || _4 === void 0 ? void 0 : _4.id) yield deep.delete((_6 = (_5 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _5 === void 0 ? void 0 : _5[0]) === null || _6 === void 0 ? void 0 : _6.id); yield deep.delete(customLinkId); debug('delete handler', yield deleteHandler(handler)); assert.equal(!!((_8 = (_7 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _7 === void 0 ? void 0 : _7[0]) === null || _8 === void 0 ? void 0 : _8.id), true); })); it(`new client by linkId`, () => __awaiter(void 0, void 0, void 0, function* () { var _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25; const debug = log.extend('HandleInsert'); const typeId = deep.idLocal('@deep-foundation/core', 'Operation'); const handleInsertTypeId = deep.idLocal('@deep-foundation/core', 'HandleInsert'); const supportsId = deep.idLocal('@deep-foundation/core', 'plv8SupportsJs'); const anyTypeId = deep.idLocal('@deep-foundation/core', 'Any'); const inserted = yield deep.insert({ type_id: 1, from_id: anyTypeId, to_id: anyTypeId }); const customLinkId = (_10 = (_9 = inserted === null || inserted === void 0 ? void 0 : inserted.data) === null || _9 === void 0 ? void 0 : _9[0]) === null || _10 === void 0 ? void 0 : _10.id; debug('customLinkId', customLinkId); const handler = yield insertHandler(handleInsertTypeId, typeId, `({deep, data}) => { const newDeep = deep.new({linkId:${yield deep.id('deep', 'admin')}}); newDeep.insert({type_id: ${customLinkId}, to_id: ${customLinkId}, from_id: ${customLinkId}, object: {linkId: newDeep.linkId}}); }`, undefined, supportsId); debug('handler', handler); try { const linkId = (_12 = (_11 = (yield deep.insert({ type_id: typeId }))) === null || _11 === void 0 ? void 0 : _11.data) === null || _12 === void 0 ? void 0 : _12[0].id; debug('linkId', linkId); debug('delete linkid', yield deep.delete({ id: { _eq: linkId } })); } catch (e) { const serializedError = serializeError(e); debug('insert error: ', JSON.stringify(serializedError, null, 2)); } const insertedByHandler = yield deep.select({ type_id: { _eq: customLinkId }, to_id: { _eq: customLinkId }, from_id: { _eq: customLinkId } }); debug('adminId', yield deep.id('deep', 'admin')); debug('insertedByHandler', insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data); debug('insertedByHandler data', (_15 = (_14 = (_13 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _13 === void 0 ? void 0 : _13[0]) === null || _14 === void 0 ? void 0 : _14.value) === null || _15 === void 0 ? void 0 : _15.value); if ((_17 = (_16 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _16 === void 0 ? void 0 : _16[0]) === null || _17 === void 0 ? void 0 : _17.id) yield deep.delete((_19 = (_18 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _18 === void 0 ? void 0 : _18[0]) === null || _19 === void 0 ? void 0 : _19.id); yield deep.delete(customLinkId); debug('delete handler', yield deleteHandler(handler)); assert.equal(!!((_21 = (_20 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _20 === void 0 ? void 0 : _20[0]) === null || _21 === void 0 ? void 0 : _21.id), true); assert.equal((_25 = (_24 = (_23 = (_22 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _22 === void 0 ? void 0 : _22[0]) === null || _23 === void 0 ? void 0 : _23.value) === null || _24 === void 0 ? void 0 : _24.value) === null || _25 === void 0 ? void 0 : _25.linkId, yield deep.id('deep', 'admin')); })); it(`new client by jwt`, () => __awaiter(void 0, void 0, void 0, function* () { var _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42; const debug = log.extend('HandleInsert'); const typeId = deep.idLocal('@deep-foundation/core', 'Operation'); const handleInsertTypeId = deep.idLocal('@deep-foundation/core', 'HandleInsert'); const supportsId = deep.idLocal('@deep-foundation/core', 'plv8SupportsJs'); const anyTypeId = deep.idLocal('@deep-foundation/core', 'Any'); const inserted = yield deep.insert({ type_id: 1, from_id: anyTypeId, to_id: anyTypeId }); const customLinkId = (_27 = (_26 = inserted === null || inserted === void 0 ? void 0 : inserted.data) === null || _26 === void 0 ? void 0 : _26[0]) === null || _27 === void 0 ? void 0 : _27.id; debug('admin Token', (yield deep.jwt({ linkId: yield deep.id('deep', 'admin') })).token); const handler = yield insertHandler(handleInsertTypeId, typeId, `({deep, data}) => { const newDeep = deep.new({token:'${(yield deep.jwt({ linkId: yield deep.id('deep', 'admin') })).token}'}); newDeep.insert({type_id: ${customLinkId}, to_id: ${customLinkId}, from_id: ${customLinkId}, object: {linkId: newDeep.linkId}}); }`, undefined, supportsId); debug('handler', handler); try { const linkId = (_29 = (_28 = (yield deep.insert({ type_id: typeId }))) === null || _28 === void 0 ? void 0 : _28.data) === null || _29 === void 0 ? void 0 : _29[0].id; debug('linkId', linkId); debug('delete linkid', yield deep.delete({ id: { _eq: linkId } })); } catch (e) { const serializedError = serializeError(e); debug('insert error: ', JSON.stringify(serializedError, null, 2)); } const insertedByHandler = yield deep.select({ type_id: { _eq: customLinkId }, to_id: { _eq: customLinkId }, from_id: { _eq: customLinkId } }); debug('adminId', yield deep.id('deep', 'admin')); debug('insertedByHandler', insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data); debug('insertedByHandler data', (_32 = (_31 = (_30 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _30 === void 0 ? void 0 : _30[0]) === null || _31 === void 0 ? void 0 : _31.value) === null || _32 === void 0 ? void 0 : _32.value); if ((_34 = (_33 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _33 === void 0 ? void 0 : _33[0]) === null || _34 === void 0 ? void 0 : _34.id) yield deep.delete((_36 = (_35 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _35 === void 0 ? void 0 : _35[0]) === null || _36 === void 0 ? void 0 : _36.id); yield deep.delete(customLinkId); debug('delete handler', yield deleteHandler(handler)); assert.equal(!!((_38 = (_37 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _37 === void 0 ? void 0 : _37[0]) === null || _38 === void 0 ? void 0 : _38.id), true); assert.equal((_42 = (_41 = (_40 = (_39 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _39 === void 0 ? void 0 : _39[0]) === null || _40 === void 0 ? void 0 : _40.value) === null || _41 === void 0 ? void 0 : _41.value) === null || _42 === void 0 ? void 0 : _42.linkId, yield deep.id('deep', 'admin')); })); it(`can`, () => __awaiter(void 0, void 0, void 0, function* () { var _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63; const debug = log.extend('HandleInsert'); const guest = yield deep.guest({}); const typeId = deep.idLocal('@deep-foundation/core', 'Operation'); const handleInsertTypeId = deep.idLocal('@deep-foundation/core', 'HandleInsert'); const supportsId = deep.idLocal('@deep-foundation/core', 'plv8SupportsJs'); const anyTypeId = deep.idLocal('@deep-foundation/core', 'Any'); const inserted = yield deep.insert({ type_id: 1, from_id: anyTypeId, to_id: anyTypeId }); const customLinkId = (_44 = (_43 = inserted === null || inserted === void 0 ? void 0 : inserted.data) === null || _43 === void 0 ? void 0 : _43[0]) === null || _44 === void 0 ? void 0 : _44.id; const admin_token = (yield deep.jwt({ linkId: yield deep.id('deep', 'admin') })).token; debug('admin Token', admin_token); const apolloClientAdmin = generateApolloClient({ path: `${process.env.DEEPLINKS_HASURA_PATH}/v1/graphql`, ssl: !!+process.env.DEEPLINKS_HASURA_SSL, token: admin_token, }); const deepAdmin = new DeepClient({ apolloClient: apolloClientAdmin }); const handler = yield insertHandler(handleInsertTypeId, typeId, `({deep, data}) => { deep.insert({type_id: ${customLinkId}, to_id: ${customLinkId}, from_id: ${customLinkId}, object: { canAdmin: deep.can(null, deep.linkId, ${deep.idLocal('@deep-foundation/core', 'AllowAdmin')}), canGuest: deep.can(null, ${guest.linkId}, ${deep.idLocal('@deep-foundation/core', 'AllowAdmin')}), linkId: String(deep.linkId), }}); }`, undefined, supportsId); debug('handler', handler); try { const linkId = (_46 = (_45 = (yield deepAdmin.insert({ type_id: typeId }))) === null || _45 === void 0 ? void 0 : _45.data) === null || _46 === void 0 ? void 0 : _46[0].id; debug('linkId', linkId); debug('delete linkid', yield deep.delete({ id: { _eq: linkId } })); } catch (e) { const serializedError = serializeError(e); debug('insert error: ', JSON.stringify(serializedError, null, 2)); } const insertedByHandler = yield deep.select({ type_id: { _eq: customLinkId }, to_id: { _eq: customLinkId }, from_id: { _eq: customLinkId } }); debug('adminId', yield deep.id('deep', 'admin')); debug('insertedByHandler', insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data); debug('insertedByHandler data', (_49 = (_48 = (_47 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _47 === void 0 ? void 0 : _47[0]) === null || _48 === void 0 ? void 0 : _48.value) === null || _49 === void 0 ? void 0 : _49.value); if ((_51 = (_50 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _50 === void 0 ? void 0 : _50[0]) === null || _51 === void 0 ? void 0 : _51.id) yield deep.delete((_53 = (_52 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _52 === void 0 ? void 0 : _52[0]) === null || _53 === void 0 ? void 0 : _53.id); yield deep.delete(customLinkId); debug('delete handler', yield deleteHandler(handler)); assert.equal(!!((_55 = (_54 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _54 === void 0 ? void 0 : _54[0]) === null || _55 === void 0 ? void 0 : _55.id), true); assert.equal((_59 = (_58 = (_57 = (_56 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _56 === void 0 ? void 0 : _56[0]) === null || _57 === void 0 ? void 0 : _57.value) === null || _58 === void 0 ? void 0 : _58.value) === null || _59 === void 0 ? void 0 : _59.canAdmin, true); assert.equal((_63 = (_62 = (_61 = (_60 = insertedByHandler === null || insertedByHandler === void 0 ? void 0 : insertedByHandler.data) === null || _60 === void 0 ? void 0 : _60[0]) === null || _61 === void 0 ? void 0 : _61.value) === null || _62 === void 0 ? void 0 : _62.value) === null || _63 === void 0 ? void 0 : _63.canGuest, false); })); it(`objectGet`, () => __awaiter(void 0, void 0, void 0, function* () { var _64, _65, _66, _67, _68, _69, _70; const { data: [{ id }] } = yield deep.insert({ type_id: deep.idLocal('@deep-foundation/core', 'Operation'), object: { data: { value: { a: 3 } } } }); const result = yield api.sql(sql `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'objectGet','[${id},["a"]]'::jsonb, '{}'::jsonb)`); log('objectGet result', (_66 = (_65 = (_64 = result === null || result === void 0 ? void 0 : result.data) === null || _64 === void 0 ? void 0 : _64.result) === null || _65 === void 0 ? void 0 : _65[1]) === null || _66 === void 0 ? void 0 : _66[0]); const selected = yield deep.select(id); log('selected', (_67 = selected === null || selected === void 0 ? void 0 : selected.data) === null || _67 === void 0 ? void 0 : _67[0]); assert.equal(3, JSON.parse((_70 = (_69 = (_68 = result === null || result === void 0 ? void 0 : result.data) === null || _68 === void 0 ? void 0 : _68.result) === null || _69 === void 0 ? void 0 : _69[1]) === null || _70 === void 0 ? void 0 : _70[0])['data']); })); it(`objectSet`, () => __awaiter(void 0, void 0, void 0, function* () { var _71, _72, _73, _74, _75, _76, _77, _78, _79; const { data: [{ id }] } = yield deep.insert({ type_id: deep.idLocal('@deep-foundation/core', 'Operation'), object: { data: { value: { a: 3 } } } }); const result = yield api.sql(sql `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'objectSet','[${id},["a"], { "b": 3 }]'::jsonb, '{}'::jsonb)`); log('objectSet result', (_73 = (_72 = (_71 = result === null || result === void 0 ? void 0 : result.data) === null || _71 === void 0 ? void 0 : _71.result) === null || _72 === void 0 ? void 0 : _72[1]) === null || _73 === void 0 ? void 0 : _73[0]); const selected = yield deep.select(id); log('selected', (_74 = selected === null || selected === void 0 ? void 0 : selected.data) === null || _74 === void 0 ? void 0 : _74[0]); assert.equal(3, (_79 = (_78 = (_77 = (_76 = (_75 = selected === null || selected === void 0 ? void 0 : selected.data) === null || _75 === void 0 ? void 0 : _75[0]) === null || _76 === void 0 ? void 0 : _76.value) === null || _77 === void 0 ? void 0 : _77.value) === null || _78 === void 0 ? void 0 : _78.a) === null || _79 === void 0 ? void 0 : _79.b); })); describe('unsafe', () => { it(`objectSet`, () => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h; const { data: [{ id }] } = yield deep.insert({ type_id: deep.idLocal('@deep-foundation/core', 'Operation'), object: { data: { a: { value: 'HelloBugFixers' }, b: { value: 'HelloBugFixers2' } } }, in: { data: { type_id: deep.idLocal('@deep-foundation/core', 'Contain'), from_id: yield deep.id('deep', 'admin') } } }); const path = ['a']; const sqlString = sql `update objects set value = jsonb_set(value, $2, $3, true) where link_id = $1`; const value = 'HelloBugFixers3'; log('sqlAll', `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'unsafe'::text, $select$["${sqlString}", ${id}, ${JSON.stringify(path)}, "${value}"]$select$::jsonb, '{}'::jsonb)`); const result = yield api.sql(sql `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'unsafe'::text, $select$["${sqlString}", ${id}, ${JSON.stringify(path)}, "${value}"]$select$::jsonb, '{}'::jsonb)`); log('select result', (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c[0]); const selected = yield deep.select(id); log('selected', (_d = selected === null || selected === void 0 ? void 0 : selected.data) === null || _d === void 0 ? void 0 : _d[0]); assert.equal((_h = (_g = (_f = (_e = selected === null || selected === void 0 ? void 0 : selected.data) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.value) === null || _g === void 0 ? void 0 : _g.value) === null || _h === void 0 ? void 0 : _h.a, 'HelloBugFixers3'); })); it(`objectGet`, () => __awaiter(void 0, void 0, void 0, function* () { var _j, _k, _l, _m, _o, _p, _q, _r, _s; const { data: [{ id }] } = yield deep.insert({ type_id: deep.idLocal('@deep-foundation/core', 'Operation'), object: { a: { value: 'HelloBugFixers' }, b: { value: 'HelloBugFixers2' } }, in: { data: { type_id: deep.idLocal('@deep-foundation/core', 'Contain'), from_id: yield deep.id('deep', 'admin') } } }); const path = ['a', 'value']; const sqlString = sql `select value#>$2 from objects where link_id = $1`; const sqlAll = sql `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'unsafe'::text, $select$["${sqlString}", ${id}, ${JSON.stringify(path)}]$select$::jsonb, '{}'::jsonb)`; log('sqlAll', sqlAll); const result = yield api.sql(sqlAll); log('select result', (_l = (_k = (_j = result === null || result === void 0 ? void 0 : result.data) === null || _j === void 0 ? void 0 : _j.result) === null || _k === void 0 ? void 0 : _k[1]) === null || _l === void 0 ? void 0 : _l[0]); const selected = yield deep.select(id); log('selected', (_m = selected === null || selected === void 0 ? void 0 : selected.data) === null || _m === void 0 ? void 0 : _m[0]); assert.equal((_s = (_r = (_q = (_p = (_o = selected === null || selected === void 0 ? void 0 : selected.data) === null || _o === void 0 ? void 0 : _o[0]) === null || _p === void 0 ? void 0 : _p.value) === null || _q === void 0 ? void 0 : _q.value) === null || _r === void 0 ? void 0 : _r.a) === null || _s === void 0 ? void 0 : _s.value, 'HelloBugFixers'); })); }); describe('select', () => { it(`select should return value`, () => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; const { data: [{ id }] } = yield deep.insert({ type_id: deep.idLocal('@deep-foundation/core', 'Operation'), string: { data: { value: 'HelloBugFixers' } }, in: { data: { type_id: deep.idLocal('@deep-foundation/core', 'Contain'), from_id: yield deep.id('deep', 'admin') } } }); const result = yield api.sql(sql `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'select'::text, '{"id": ${id}}'::jsonb, '{}'::jsonb)`); log('select result', (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c[0]); const value = (_j = (_h = (_g = JSON.parse((_f = (_e = (_d = result === null || result === void 0 ? void 0 : result.data) === null || _d === void 0 ? void 0 : _d.result) === null || _e === void 0 ? void 0 : _e[1]) === null || _f === void 0 ? void 0 : _f[0])) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.value; const selected = yield deep.select(id); log('selected', (_k = selected === null || selected === void 0 ? void 0 : selected.data) === null || _k === void 0 ? void 0 : _k[0]); assert.equal(value === null || value === void 0 ? void 0 : value.value, 'HelloBugFixers'); assert.equal(value === null || value === void 0 ? void 0 : value.id, (_o = (_m = (_l = selected === null || selected === void 0 ? void 0 : selected.data) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.value) === null || _o === void 0 ? void 0 : _o.id); })); describe('number', () => { it(`number: { value: number }}`, () => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const { data: [{ id }] } = yield deep.insert({ type_id: deep.idLocal('@deep-foundation/core', 'Operation'), number: { data: { value: 1515 } }, in: { data: { type_id: deep.idLocal('@deep-foundation/core', 'Contain'), from_id: yield deep.id('deep', 'admin') } } }); const result = yield api.sql(sql `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'select'::text, '{"type_id": ${deep.idLocal('@deep-foundation/core', 'Operation')}, "number": {"value": 1515}}'::jsonb, '{}'::jsonb)`); log('select result', (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c[0]); const value = (_j = (_h = (_g = JSON.parse((_f = (_e = (_d = result === null || result === void 0 ? void 0 : result.data) === null || _d === void 0 ? void 0 : _d.result) === null || _e === void 0 ? void 0 : _e[1]) === null || _f === void 0 ? void 0 : _f[0])) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.value; const selected = yield deep.select(id); log('selected', (_k = selected === null || selected === void 0 ? void 0 : selected.data) === null || _k === void 0 ? void 0 : _k[0]); yield deep.delete(id); assert.equal(value === null || value === void 0 ? void 0 : value.value, 1515); })); it(`number: { value: { "_in": [ number, number ] }}`, () => __awaiter(void 0, void 0, void 0, function* () { var _l, _m, _o, _p, _q, _r, _s, _t, _u, _v; const { data: [{ id }] } = yield deep.insert({ type_id: deep.idLocal('@deep-foundation/core', 'Operation'), number: { data: { value: 1515 } }, in: { data: { type_id: deep.idLocal('@deep-foundation/core', 'Contain'), from_id: yield deep.id('deep', 'admin') } } }); const result = yield api.sql(sql `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'select'::text, '{"type_id": ${deep.idLocal('@deep-foundation/core', 'Operation')}, "number": {"value": { "_in": [ 1515, 12 ]}}}'::jsonb, '{}'::jsonb)`); log('select result', (_o = (_m = (_l = result === null || result === void 0 ? void 0 : result.data) === null || _l === void 0 ? void 0 : _l.result) === null || _m === void 0 ? void 0 : _m[1]) === null || _o === void 0 ? void 0 : _o[0]); const value = (_u = (_t = (_s = JSON.parse((_r = (_q = (_p = result === null || result === void 0 ? void 0 : result.data) === null || _p === void 0 ? void 0 : _p.result) === null || _q === void 0 ? void 0 : _q[1]) === null || _r === void 0 ? void 0 : _r[0])) === null || _s === void 0 ? void 0 : _s.data) === null || _t === void 0 ? void 0 : _t[0]) === null || _u === void 0 ? void 0 : _u.value; const selected = yield deep.select(id); log('selected', (_v = selected === null || selected === void 0 ? void 0 : selected.data) === null || _v === void 0 ? void 0 : _v[0]); yield deep.delete(id); assert.equal(value === null || value === void 0 ? void 0 : value.value, 1515); })); it(`number: number`, () => __awaiter(void 0, void 0, void 0, function* () { var _w, _x, _y, _z, _0, _1, _2, _3, _4, _5; const { data: [{ id }] } = yield deep.insert({ type_id: deep.idLocal('@deep-foundation/core', 'Operation'), number: { data: { value: 1515 } }, in: { data: { type_id: deep.idLocal('@deep-foundation/core', 'Contain'), from_id: yield deep.id('deep', 'admin') } } }); const result = yield api.sql(sql `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'select'::text, '{"type_id": ${deep.idLocal('@deep-foundation/core', 'Operation')}, "number": 1515}'::jsonb, '{}'::jsonb)`); log('select result', (_y = (_x = (_w = result === null || result === void 0 ? void 0 : result.data) === null || _w === void 0 ? void 0 : _w.result) === null || _x === void 0 ? void 0 : _x[1]) === null || _y === void 0 ? void 0 : _y[0]); const value = (_4 = (_3 = (_2 = JSON.parse((_1 = (_0 = (_z = result === null || result === void 0 ? void 0 : result.data) === null || _z === void 0 ? void 0 : _z.result) === null || _0 === void 0 ? void 0 : _0[1]) === null || _1 === void 0 ? void 0 : _1[0])) === null || _2 === void 0 ? void 0 : _2.data) === null || _3 === void 0 ? void 0 : _3[0]) === null || _4 === void 0 ? void 0 : _4.value; const selected = yield deep.select(id); log('selected', (_5 = selected === null || selected === void 0 ? void 0 : selected.data) === null || _5 === void 0 ? void 0 : _5[0]); yield deep.delete(id); assert.equal(value === null || value === void 0 ? void 0 : value.value, 1515); })); it(`number: { "_in": [ number, number ]}`, () => __awaiter(void 0, void 0, void 0, function* () { var _6, _7, _8, _9, _10, _11, _12, _13, _14, _15; const { data: [{ id }] } = yield deep.insert({ type_id: deep.idLocal('@deep-foundation/core', 'Operation'), number: { data: { value: 1515 } }, in: { data: { type_id: deep.idLocal('@deep-foundation/core', 'Contain'), from_id: yield deep.id('deep', 'admin') } } }); const result = yield api.sql(sql `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'select'::text, '{"type_id": ${deep.idLocal('@deep-foundation/core', 'Operation')}, "number": { "_in": [ 1515, 9999 ]}}'::jsonb, '{}'::jsonb)`); log('select result', (_8 = (_7 = (_6 = result === null || result === void 0 ? void 0 : result.data) === null || _6 === void 0 ? void 0 : _6.result) === null || _7 === void 0 ? void 0 : _7[1]) === null || _8 === void 0 ? void 0 : _8[0]); const value = (_14 = (_13 = (_12 = JSON.parse((_11 = (_10 = (_9 = result === null || result === void 0 ? void 0 : result.data) === null || _9 === void 0 ? void 0 : _9.result) === null || _10 === void 0 ? void 0 : _10[1]) === null || _11 === void 0 ? void 0 : _11[0])) === null || _12 === void 0 ? void 0 : _12.data) === null || _13 === void 0 ? void 0 : _13[0]) === null || _14 === void 0 ? void 0 : _14.value; const selected = yield deep.select(id); log('selected', (_15 = selected === null || selected === void 0 ? void 0 : selected.data) === null || _15 === void 0 ? void 0 : _15[0]); yield deep.delete(id); assert.equal(value === null || value === void 0 ? void 0 : value.value, 1515); })); }); describe('string', () => { it(`string: { value: string }`, () => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const { data: [{ id }] } = yield deep.insert({ type_id: deep.idLocal('@deep-foundation/core', 'Operation'), string: { data: { value: 'HelloBugFixers' } }, in: { data: { type_id: deep.idLocal('@deep-foundation/core', 'Contain'), from_id: yield deep.id('deep', 'admin') } } }); const result = yield api.sql(sql `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'select'::text, '{"type_id": ${deep.idLocal('@deep-foundation/core', 'Operation')}, "string": {"value": "HelloBugFixers"}}'::jsonb, '{}'::jsonb)`); log('select result', (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c[0]); const value = (_j = (_h = (_g = JSON.parse((_f = (_e = (_d = result === null || result === void 0 ? void 0 : result.data) === null || _d === void 0 ? void 0 : _d.result) === null || _e === void 0 ? void 0 : _e[1]) === null || _f === void 0 ? void 0 : _f[0])) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.value; const selected = yield deep.select(id); log('selected', (_k = selected === null || selected === void 0 ? void 0 : selected.data) === null || _k === void 0 ? void 0 : _k[0]); yield deep.delete(id); assert.equal(value === null || value === void 0 ? void 0 : value.value, 'HelloBugFixers'); })); it(`string: { value: { "_in": [ string, string ] }}`, () => __awaiter(void 0, void 0, void 0, function* () { var _l, _m, _o, _p, _q, _r, _s, _t, _u, _v; const { data: [{ id }] } = yield deep.insert({ type_id: deep.idLocal('@deep-foundation/core', 'Operation'), string: { data: { value: 'HelloBugFixers2' } }, in: { data: { type_id: deep.idLocal('@deep-foundation/core', 'Contain'), from_id: yield deep.id('deep', 'admin') } } }); const result = yield api.sql(sql `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'select'::text, '{"type_id": ${deep.idLocal('@deep-foundation/core', 'Operation')}, "string": {"value": { "_in": [ "HelloBugFixers2", "noNoNO" ]}}}'::jsonb, '{}'::jsonb)`); log('select result', (_o = (_m = (_l = result === null || result === void 0 ? void 0 : result.data) === null || _l === void 0 ? void 0 : _l.result) === null || _m === void 0 ? void 0 : _m[1]) === null || _o === void 0 ? void 0 : _o[0]); const value = (_u = (_t = (_s = JSON.parse((_r = (_q = (_p = result === null || result === void 0 ? void 0 : result.data) === null || _p === void 0 ? void 0 : _p.result) === null || _q === void 0 ? void 0 : _q[1]) === null || _r === void 0 ? void 0 : _r[0])) === null || _s === void 0 ? void 0 : _s.data) === null || _t === void 0 ? void 0 : _t[0]) === null || _u === void 0 ? void 0 : _u.value; const selected = yield deep.select(id); log('selected', (_v = selected === null || selected === void 0 ? void 0 : selected.data) === null || _v === void 0 ? void 0 : _v[0]); yield deep.delete(id); assert.equal(value === null || value === void 0 ? void 0 : value.value, 'HelloBugFixers2'); })); it(`string: 'string'`, () => __awaiter(void 0, void 0, void 0, function* () { var _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8; const { data: [{ id }] } = yield deep.insert({ type_id: deep.idLocal('@deep-foundation/core', 'Operation'), string: { data: { value: 'HelloBugFixersTest' } }, in: { data: { type_id: deep.idLocal('@deep-foundation/core', 'Contain'), from_id: yield deep.id('deep', 'admin') } } }); const { data: [{ id: id2 }] } = yield deep.insert({ type_id: deep.idLocal('@deep-foundation/core', 'Operation'), string: { data: { value: 'hellobugfixerstest' } }, in: { data: { type_id: deep.idLocal('@deep-foundation/core', 'Contain'), from_id: yield deep.id('deep', 'admin') } } }); const result = yield api.sql(sql `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'select'::text, '{"type_id": ${deep.idLocal('@deep-foundation/core', 'Operation')}, "string": "hellobugfixerstest"}'::jsonb, '{}'::jsonb)`); log('select result', (_w = result === null || result === void 0 ? void 0 : result.data) === null || _w === void 0 ? void 0 : _w.result); log('select result?.[1]', (_y = (_x = result === null || result === void 0 ? void 0 : result.data) === null || _x === void 0 ? void 0 : _x.result) === null || _y === void 0 ? void 0 : _y[1]); log('select result?.[1]?.[0]', (_1 = (_0 = (_z = result === null || result === void 0 ? void 0 : result.data) === null || _z === void 0 ? void 0 : _z.result) === null || _0 === void 0 ? void 0 : _0[1]) === null || _1 === void 0 ? void 0 : _1[0]); const value = (_7 = (_6 = (_5 = JSON.parse((_4 = (_3 = (_2 = result === null || result === void 0 ? void 0 : result.data) === null || _2 === void 0 ? void 0 : _2.result) === null || _3 === void 0 ? void 0 : _3[1]) === null || _4 === void 0 ? void 0 : _4[0])) === null || _5 === void 0 ? void 0 : _5.data) === null || _6 === void 0 ? void 0 : _6[0]) === null || _7 === void 0 ? void 0 : _7.value; const selected = yield deep.select(id2); log('selected', (_8 = selected === null || selected === void 0 ? void 0 : selected.data) === null || _8 === void 0 ? void 0 : _8[0]); yield deep.delete(id); yield deep.delete(id2); assert.equal(value === null || value === void 0 ? void 0 : value.value, 'hellobugfixerstest'); })); it(`string: { "_in": ['string', 'string'] }`, () => __awaiter(void 0, void 0, void 0, function* () { var _9, _10, _11, _12, _13, _14, _15, _16, _17, _18; const { data: [{ id }] } = yield deep.insert({ type_id: deep.idLocal('@deep-foundation/core', 'Operation'), string: { data: { value: 'HelloBugFixersTest' } }, in: { data: { type_id: deep.idLocal('@deep-foundation/core', 'Contain'), from_id: yield deep.id('deep', 'admin') } } }); const result = yield api.sql(sql `select links__sync__handlers__deep__client(${yield deep.id('deep', 'admin')}::bigint, 'select'::text, '{"type_id": ${deep.idLocal('@deep-foundation/core', 'Operation')}, "string": { "_in": ["hellobugfixerstest", "goodbyebugfixerstest"]}}'::jsonb, '{}'::jsonb)`); log('select result', (_11 = (_10 = (_9 = result === null || result === void 0 ? void 0 : result.data) === null || _9 === void 0 ? void 0 : _9.result) === null || _10 === void 0 ? void 0 : _10[1]) === null || _11 === void 0 ? void 0 : _11[0]); const value = (_17 = (_16 = (_15 = JSON.parse((_14 = (_13 = (_12 = result === null || result === void 0 ? void 0 : result.data) === null || _12 === void 0 ? void 0 : _12.result) === null || _13 === void 0 ? void 0 : _13[1]) === null || _14 === void 0 ? void 0 : _14[0])) === null || _15 === void 0 ? void 0 : _15.data) === null || _16 === void 0 ? void 0 : _16[0]) === null || _17 === void 0 ? void 0 : _17.value; cons