zeed 1.4.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{args-FLoL3OKJ.d.cts → args-CEjib9V9.d.mts} +1 -1
- package/dist/{args-WC9q5kz2.d.mts → args-DEig-jw4.d.cts} +1 -1
- package/dist/{clipboard-BkUO-syY.d.mts → clipboard-BusqmLLY.d.cts} +1 -1
- package/dist/{clipboard-Cfpr331X.d.cts → clipboard-DcuuFRwa.d.mts} +1 -1
- package/dist/common/exec/index.d.cts +2 -2
- package/dist/common/exec/index.d.mts +2 -2
- package/dist/common/exec/promise.d.cts +1 -1
- package/dist/common/exec/promise.d.mts +1 -1
- package/dist/common/exec/throttle-debounce.d.cts +1 -1
- package/dist/common/exec/throttle-debounce.d.mts +1 -1
- package/dist/common/index.cjs +21 -0
- package/dist/common/index.d.cts +14 -11
- package/dist/common/index.d.mts +15 -12
- package/dist/common/index.mjs +4 -1
- package/dist/common/msg/rpc.cjs +8 -8
- package/dist/common/msg/rpc.cjs.map +1 -1
- package/dist/common/msg/rpc.mjs +8 -8
- package/dist/common/msg/rpc.mjs.map +1 -1
- package/dist/common/schema/export-json-schema.cjs +40 -31
- package/dist/common/schema/export-json-schema.cjs.map +1 -1
- package/dist/common/schema/export-json-schema.mjs +40 -31
- package/dist/common/schema/export-json-schema.mjs.map +1 -1
- package/dist/common/schema/index.cjs +21 -0
- package/dist/common/schema/index.d.cts +6 -3
- package/dist/common/schema/index.d.mts +7 -4
- package/dist/common/schema/index.mjs +4 -1
- package/dist/common/schema/sql/expr.cjs +128 -0
- package/dist/common/schema/sql/expr.cjs.map +1 -0
- package/dist/common/schema/sql/expr.d.cts +2 -0
- package/dist/common/schema/sql/expr.d.mts +2 -0
- package/dist/common/schema/sql/expr.mjs +115 -0
- package/dist/common/schema/sql/expr.mjs.map +1 -0
- package/dist/common/schema/sql/index.cjs +23 -0
- package/dist/common/schema/sql/index.d.cts +4 -0
- package/dist/common/schema/sql/index.d.mts +4 -0
- package/dist/common/schema/sql/index.mjs +5 -0
- package/dist/common/schema/sql/select.cjs +143 -0
- package/dist/common/schema/sql/select.cjs.map +1 -0
- package/dist/common/schema/sql/select.d.cts +2 -0
- package/dist/common/schema/sql/select.d.mts +2 -0
- package/dist/common/schema/sql/select.mjs +139 -0
- package/dist/common/schema/sql/select.mjs.map +1 -0
- package/dist/common/schema/sql/table.cjs +23 -0
- package/dist/common/schema/sql/table.cjs.map +1 -0
- package/dist/common/schema/sql/table.d.cts +2 -0
- package/dist/common/schema/sql/table.d.mts +2 -0
- package/dist/common/schema/sql/table.mjs +20 -0
- package/dist/common/schema/sql/table.mjs.map +1 -0
- package/dist/common/schema/type-test.d.cts +1 -1
- package/dist/common/schema/type-test.d.mts +1 -1
- package/dist/common/schema/utils.d.cts +1 -1
- package/dist/common/schema/utils.d.mts +1 -1
- package/dist/common/schema/z.d.mts +1 -1
- package/dist/common/storage/index.d.cts +1 -1
- package/dist/common/storage/index.d.mts +1 -1
- package/dist/common/storage/memstorage.d.cts +1 -1
- package/dist/common/storage/memstorage.d.mts +1 -1
- package/dist/common/test.d.cts +1 -1
- package/dist/common/test.d.mts +1 -1
- package/dist/common/time.d.cts +1 -1
- package/dist/common/time.d.mts +1 -1
- package/dist/common/timeout.d.cts +1 -1
- package/dist/common/timeout.d.mts +1 -1
- package/dist/common/utils.d.cts +1 -1
- package/dist/common/utils.d.mts +1 -1
- package/dist/common/uuid.d.cts +1 -1
- package/dist/common/uuid.d.mts +1 -1
- package/dist/{crypto-CyTV7Qce.d.cts → crypto-D68rVmvU.d.mts} +1 -1
- package/dist/{crypto-LT7EC5_d.d.mts → crypto-KzGHoCJE.d.cts} +1 -1
- package/dist/{env-B3vOiVY8.d.cts → env-BJXdwBKq.d.mts} +1 -1
- package/dist/{env-C3npYe8w.d.mts → env-HsOnA_yK.d.cts} +1 -1
- package/dist/expr-CCKrqOw1.d.mts +25 -0
- package/dist/expr-yYgSeBZ3.d.cts +25 -0
- package/dist/{files-CDNKX9VI.d.mts → files-4O-PxnAC.d.cts} +1 -1
- package/dist/{files-DdI9UZvg.d.cts → files-BlpxqSTT.d.mts} +1 -1
- package/dist/{files-async-1V0bu_ca.d.cts → files-async-DFLC-Nkd.d.cts} +1 -1
- package/dist/{files-async-cBMkRwsu.d.mts → files-async-DfuEEDjH.d.mts} +1 -1
- package/dist/{filestorage-CXQ9MzeW.d.cts → filestorage-BjeBZEAs.d.cts} +1 -1
- package/dist/{filestorage-YzM2z9sU.d.mts → filestorage-CmfztpWm.d.mts} +1 -1
- package/dist/{fs-DHJ9AqUk.d.cts → fs-D837bjRT.d.cts} +1 -1
- package/dist/{fs-DgjZdpuF.d.mts → fs-DlYLapik.d.mts} +1 -1
- package/dist/{glob-Bfs7ZS_i.d.mts → glob-5yW09dkR.d.mts} +1 -1
- package/dist/{glob-Bt150jOY.d.cts → glob-CZaZPqiy.d.cts} +1 -1
- package/dist/index.all.cjs +21 -0
- package/dist/index.all.d.cts +28 -25
- package/dist/index.all.d.mts +29 -26
- package/dist/index.all.mjs +4 -1
- package/dist/index.browser.cjs +21 -0
- package/dist/index.browser.d.cts +14 -11
- package/dist/index.browser.d.mts +15 -12
- package/dist/index.browser.mjs +4 -1
- package/dist/index.jsr.d.cts +4 -4
- package/dist/index.jsr.d.mts +4 -4
- package/dist/index.node.cjs +21 -0
- package/dist/index.node.d.cts +28 -25
- package/dist/index.node.d.mts +29 -26
- package/dist/index.node.mjs +4 -1
- package/dist/{log-file-bsTsc9KM.d.cts → log-file-DwEDms1F.d.cts} +2 -2
- package/dist/{log-file-DTuImomJ.d.mts → log-file-QV1unm3z.d.mts} +2 -2
- package/dist/{log-file-rotation-_YruAcNc.d.cts → log-file-rotation-BpZxXYlU.d.cts} +2 -2
- package/dist/{log-file-rotation-FBmtp_Uz.d.mts → log-file-rotation-DanrO_2y.d.mts} +2 -2
- package/dist/{log-node-DlrXl3QO.d.mts → log-node-BSn7RqAc.d.mts} +1 -1
- package/dist/{log-node-Dk948mHX.d.cts → log-node-D_fiJL6x.d.cts} +1 -1
- package/dist/{log-rotation-CkyjZbK5.d.mts → log-rotation-BdGakFya.d.cts} +1 -1
- package/dist/{log-rotation-_d7iRm9s.d.cts → log-rotation-Ce4e-8LN.d.mts} +1 -1
- package/dist/{log-util-2Ls76P-0.d.cts → log-util-C0U3zCjw.d.cts} +1 -1
- package/dist/{log-util-Da_d19f8.d.mts → log-util-Da_UCcmt.d.mts} +1 -1
- package/dist/{memstorage-D5A9FwiP.d.mts → memstorage-BhWXthO8.d.mts} +1 -1
- package/dist/{memstorage-BcjQLdaQ.d.cts → memstorage-tvlWDYgS.d.cts} +1 -1
- package/dist/node/args.d.cts +1 -1
- package/dist/node/args.d.mts +1 -1
- package/dist/node/clipboard.d.cts +1 -1
- package/dist/node/clipboard.d.mts +1 -1
- package/dist/node/crypto.d.cts +1 -1
- package/dist/node/crypto.d.mts +1 -1
- package/dist/node/env.d.cts +1 -1
- package/dist/node/env.d.mts +1 -1
- package/dist/node/files-async.d.cts +1 -1
- package/dist/node/files-async.d.mts +1 -1
- package/dist/node/files.d.cts +1 -1
- package/dist/node/files.d.mts +1 -1
- package/dist/node/filestorage.d.cts +1 -1
- package/dist/node/filestorage.d.mts +1 -1
- package/dist/node/fs.d.cts +1 -1
- package/dist/node/fs.d.mts +1 -1
- package/dist/node/glob.d.cts +1 -1
- package/dist/node/glob.d.mts +1 -1
- package/dist/node/index.d.cts +14 -14
- package/dist/node/index.d.mts +14 -14
- package/dist/node/log/index.d.cts +5 -5
- package/dist/node/log/index.d.mts +5 -5
- package/dist/node/log/log-file-rotation.d.cts +1 -1
- package/dist/node/log/log-file-rotation.d.mts +1 -1
- package/dist/node/log/log-file.d.cts +1 -1
- package/dist/node/log/log-file.d.mts +1 -1
- package/dist/node/log/log-node.cjs +4 -13
- package/dist/node/log/log-node.cjs.map +1 -1
- package/dist/node/log/log-node.d.cts +1 -1
- package/dist/node/log/log-node.d.mts +1 -1
- package/dist/node/log/log-node.mjs +4 -13
- package/dist/node/log/log-node.mjs.map +1 -1
- package/dist/node/log/log-rotation.d.cts +1 -1
- package/dist/node/log/log-rotation.d.mts +1 -1
- package/dist/node/log/log-util.d.cts +1 -1
- package/dist/node/log/log-util.d.mts +1 -1
- package/dist/{promise-DGgiRckN.d.cts → promise-CU_CENbU.d.cts} +1 -1
- package/dist/{promise-MH3xAy4S.d.mts → promise-CoWXgo4w.d.mts} +1 -1
- package/dist/select-DrciHdk_.d.cts +52 -0
- package/dist/select-F2KpP6mo.d.mts +52 -0
- package/dist/table-Cr8tjDIL.d.mts +19 -0
- package/dist/table-IkLXirT-.d.cts +19 -0
- package/dist/{test-CAhm15f4.d.mts → test-DcXa0MeX.d.cts} +1 -1
- package/dist/{test-D2plOVHF.d.cts → test-jZsc7P2c.d.mts} +1 -1
- package/dist/{throttle-debounce-BLFxAZ8W.d.mts → throttle-debounce-CCh0F100.d.mts} +1 -1
- package/dist/{throttle-debounce-Psb0ay1r.d.cts → throttle-debounce-DyFiyoAk.d.cts} +1 -1
- package/dist/{time-BfKJBbym.d.cts → time-BgFZe9ys.d.cts} +1 -1
- package/dist/{time-DxE-vjjw.d.mts → time-DSV_k3mG.d.mts} +1 -1
- package/dist/{timeout-CnUk6Ruj.d.mts → timeout-DDSSNZY8.d.mts} +1 -1
- package/dist/{timeout-CpFcK8MD.d.cts → timeout-E3ZQbJgK.d.cts} +1 -1
- package/dist/{type-test-BiKyEZkc.d.mts → type-test-BvzWDJz3.d.mts} +1 -1
- package/dist/{type-test-sM7QpfQU.d.cts → type-test-CBK-iJ9d.d.cts} +1 -1
- package/dist/{utils-B8DsVgFr.d.mts → utils-1RyCGkpQ.d.mts} +1 -1
- package/dist/{utils-BfZkD2Pt.d.mts → utils-6Culwiaf.d.cts} +1 -1
- package/dist/{utils-DHQBNh-Z.d.cts → utils-CDJihcg3.d.mts} +1 -1
- package/dist/{utils-Bctk_WhH.d.cts → utils-nCQklGHV.d.cts} +1 -1
- package/dist/{uuid-Cusm2nIK.d.cts → uuid-CKFZfSff.d.mts} +1 -1
- package/dist/{uuid-ININPGKB.d.mts → uuid-D42A8UdP.d.cts} +1 -1
- package/dist/z-C0fpNWZg.d.cts +1 -0
- package/dist/z-D_jezYmm.d.mts +1 -0
- package/dist/{z-collection-BmuBin--.d.mts → z-collection-BSfgRU0Q.d.mts} +1 -1
- package/package.json +23 -27
- package/src/common/bin/lib0/decoding.spec.ts +84 -1
- package/src/common/bin/lib0/encoding.spec.ts +109 -1
- package/src/common/bin/lib0/string.spec.ts +45 -1
- package/src/common/crypto/crypto.spec.ts +7 -0
- package/src/common/crypto/xaes.spec.ts +48 -0
- package/src/common/data/deep.spec.ts +45 -0
- package/src/common/data/regexp.spec.ts +30 -0
- package/src/common/schema/export-json-schema.spec.ts +11 -7
- package/src/common/schema/export-json-schema.ts +59 -52
- package/src/common/schema/_sandbox/sandbox-inherit.ts +0 -13
- package/src/common/schema/_sandbox/sandbox.ts +0 -42
- package/src/common/schema/_sandbox/sandbox.xspec.ts +0 -45
- /package/dist/{index-BH1nuHdZ.d.cts → index-CIABef8t.d.mts} +0 -0
- /package/dist/{index-BL7o4fG9.d.cts → index-CliqZ9rj.d.mts} +0 -0
- /package/dist/{index-CP2eJYlK.d.mts → index-D6xqj1Qx.d.cts} +0 -0
- /package/dist/{index-DjOaHFU3.d.mts → index-DHFfG4yr.d.cts} +0 -0
- /package/dist/{index-sViox9YW.d.mts → index-N-OgGgfF.d.mts} +0 -0
- /package/dist/{z-ClMox7qS.d.mts → index-WOw4GVZo.d.cts} +0 -0
- /package/dist/{z-dtM4F8Lo.d.cts → index-luywJTzJ.d.mts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.mjs","names":[],"sources":["../../../src/common/msg/rpc.ts"],"sourcesContent":["// From https://github.com/antfu/birpc/blob/main/src/index.ts MIT\n\nimport type { UseStringHashPool } from '../data/string-hash-pool'\nimport type { LoggerInterface } from '../log/log-base'\nimport type { Pipe } from './pipe'\nimport { createPromise } from '../exec/promise'\n\nexport type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never\nexport type ReturnType<T> = T extends (...args: any) => infer R ? R : never\n\nexport interface RPCOptionsBasic extends Pipe {\n /** No return values expected */\n onlyEvents?: boolean\n /** Maximum timeout for waiting for response, in milliseconds */\n timeout?: number\n /** Custom logger */\n log?: LoggerInterface\n /** Custom error handler */\n onError?: (error: Error, functionName: string, args: any[]) => boolean | void\n /** Custom error handler for timeouts */\n onTimeoutError?: (functionName: string, args: any[]) => boolean | void\n /** Throw execptions. Default: true */\n exceptions?: boolean\n /** */\n stringHashPool?: UseStringHashPool\n}\n\nexport interface RPCOptions<Remote> extends RPCOptionsBasic {\n // /** No return values expected */\n // onlyEvents?: boolean\n /** Names of remote functions that do not need response. */\n eventNames?: (keyof Remote)[]\n}\n\nexport interface RPCFn<T> {\n /** Call the remote function and wait for the result. */\n (...args: ArgumentsType<T>): Promise<Awaited<ReturnType<T>>>\n /** Send event without asking for response */\n asEvent: (...args: ArgumentsType<T>) => void\n}\n\nexport type RPCReturn<RemoteFunctions> = {\n [K in keyof RemoteFunctions]: RPCFn<RemoteFunctions[K]>\n}\n\nlet rpcCounter = 1\n\nexport enum RPCMode {\n request = 1,\n event = 2,\n resolve = 3,\n reject = 4,\n}\n\nexport type RPCMessage = [\n mode: RPCMode,\n id: number,\n method: string | number | any,\n ...any,\n]\n\nconst defaultSerialize = (i: any) => i\nconst defaultDeserialize = defaultSerialize\n\nfunction setupRPCBasic(options: RPCOptionsBasic, functions: Record<string, (...args: any) => Promise<any>>, eventNames: string[] = []) {\n const {\n log,\n post,\n on,\n serialize = defaultSerialize,\n deserialize = defaultDeserialize,\n timeout = 60e3,\n onError,\n onTimeoutError,\n onlyEvents = false,\n exceptions = true,\n stringHashPool,\n } = options\n\n if (stringHashPool) {\n Object.keys(functions).forEach(stringHashPool.hash)\n }\n\n function checkEventNames(eventNames: string[]) {\n // eventNames.forEach((n) => {\n // if (functions[n] == null)\n // throw new Error(`event name ${n} has no registered function`)\n // })\n }\n\n checkEventNames(eventNames)\n\n function registerFunctions(additionalFunctions: any) {\n Object.assign(functions, additionalFunctions ?? {})\n if (stringHashPool)\n Object.keys(additionalFunctions).forEach(stringHashPool.hash)\n }\n\n function registerEventNames(additionalEventNames: string[]) {\n checkEventNames(additionalEventNames)\n eventNames.push(...additionalEventNames)\n }\n\n const rpcPromiseMap = new Map<number, {\n resolve: (...args: any) => any\n reject: (...args: any) => any\n timeoutId: Parameters<typeof clearTimeout>[0]\n }>()\n\n on(async (data) => {\n try {\n const msg = await deserialize(data) as RPCMessage\n const mode = msg?.[0]\n const id = mode === RPCMode.event ? 0 : msg?.[1]\n const [method, ...args] = msg.slice(mode === RPCMode.event ? 1 : 2)\n const methodName = stringHashPool?.stringForHash(method) ?? method\n if (mode === RPCMode.request || mode === RPCMode.event) {\n let result, error: any\n if (method != null) {\n try {\n const fn = functions[methodName]\n result = await fn(...args)\n }\n catch (e) {\n error = String(e)\n }\n }\n else {\n error = 'Method implementation missing'\n }\n if (error) {\n log?.warn('error', msg, error)\n onError?.(error, method ?? '', args)\n }\n if (id > 0) {\n const data = await serialize(error\n ? [RPCMode.reject, id, error]\n : [RPCMode.resolve, id, result])\n await post(data)\n }\n }\n else if (id) {\n const promise = rpcPromiseMap.get(id)\n if (promise != null) {\n clearTimeout(promise.timeoutId)\n if (mode === RPCMode.reject && exceptions === true)\n promise.reject(method)\n else\n promise.resolve(method)\n }\n rpcPromiseMap.delete(id)\n }\n }\n catch (err) {\n log?.warn('Error on handling RPC data. Invalid?', err, data)\n }\n })\n\n const proxyHandler = {\n get(_: any, methodName: string) {\n const method = stringHashPool?.hash(methodName) ?? methodName\n const sendEvent = async (...args: any[]) => await post(await serialize([RPCMode.event, method, ...args]))\n\n if (onlyEvents || eventNames.includes(methodName)) {\n sendEvent.asEvent = sendEvent\n return sendEvent\n }\n\n const sendCall = async (...args: any[]) => {\n const [promise, resolve, reject] = createPromise()\n const id = rpcCounter++\n\n let timeoutId: any\n if (timeout >= 0) {\n timeoutId = setTimeout(() => {\n try {\n // Custom onTimeoutError handler can throw its own error too\n onTimeoutError?.(methodName, args)\n throw new Error(`rpc timeout on calling \"${methodName}\"`)\n }\n catch (e) {\n if (exceptions === true)\n reject(e)\n else\n resolve(undefined)\n }\n rpcPromiseMap.delete(id)\n\n // Garbage Collection https://jakearchibald.com/2024/garbage-collection-and-closures/\n clearTimeout(timeoutId)\n timeoutId = undefined\n }, timeout).unref?.()\n }\n\n rpcPromiseMap.set(id, { resolve, reject, timeoutId })\n const data = await serialize([RPCMode.request, id, method, ...args])\n await post(data)\n return promise\n }\n sendCall.asEvent = sendEvent\n return sendCall\n },\n }\n\n return {\n post,\n serialize,\n rpcPromiseMap,\n proxyHandler,\n registerFunctions,\n registerEventNames,\n }\n}\n\nexport function useRPC<LocalFunctions, RemoteFunctions = LocalFunctions>(\n functions: LocalFunctions,\n options: RPCOptions<RemoteFunctions>,\n): RPCReturn<RemoteFunctions> {\n const { eventNames = [] } = options\n\n const { proxyHandler } = setupRPCBasic(options, functions as any, eventNames as any)\n\n return new Proxy({}, proxyHandler)\n}\n\nexport function useRPCHub(options: RPCOptionsBasic) {\n const eventNames: string[] = []\n const functions: Record<string, any> = {}\n\n const {\n proxyHandler,\n registerFunctions,\n registerEventNames,\n } = setupRPCBasic(options, functions, eventNames)\n\n function createRPCProxy() {\n return new Proxy({}, proxyHandler)\n }\n\n return function<LocalFunctions, RemoteFunctions = LocalFunctions>(\n additionalFunctions?: LocalFunctions,\n additionalEventNames: string[] = [],\n ): RPCReturn<RemoteFunctions> {\n registerFunctions(additionalFunctions ?? {})\n registerEventNames(additionalEventNames)\n return createRPCProxy()\n }\n}\n\nexport type UseRPCHubType = ReturnType<typeof useRPCHub>\n\n// Syntax test case\n// async function _demo() {\n// const hub: UseRPCHubType = {} as any\n// const x = hub({\n// test(name: string): string {\n// return name\n// },\n// })\n// await x.test('dsd')\n// }\n"],"mappings":";;;AA6C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AO;;AAET,YAAS,UAAU;AACnB,UAAO;KAEV;EAOC;EACA;EACD;;AAGH,SAAgB,OACd,WACA,SAC4B;CAC5B,MAAM,EAAE,aAAa,EAAE,KAAK;CAE5B,MAAM,EAAE,iBAAiB,cAAc,SAAS,WAAkB,WAAkB;AAEpF,QAAO,IAAI,MAAM,EAAE,EAAE,aAAa;;AAGpC,SAAgB,UAAU,SAA0B;CAIlD,MAAM,EACJ,cACA,mBACA,uBACE,cAAc,SANqB,EAAE,EADZ,EAAE,CAOkB;CAEjD,SAAS,iBAAiB;AACxB,SAAO,IAAI,MAAM,EAAE,EAAE,aAAa;;AAGpC,QAAO,SACL,qBACA,uBAAiC,EAAE,EACP;AAC5B,oBAAkB,uBAAuB,EAAE,CAAC;AAC5C,qBAAmB,qBAAqB;AACxC,SAAO,gBAAgB"}
|
|
1
|
+
{"version":3,"file":"rpc.mjs","names":[],"sources":["../../../src/common/msg/rpc.ts"],"sourcesContent":["// From https://github.com/antfu/birpc/blob/main/src/index.ts MIT\n\nimport type { UseStringHashPool } from '../data/string-hash-pool'\nimport type { LoggerInterface } from '../log/log-base'\nimport type { Pipe } from './pipe'\nimport { createPromise } from '../exec/promise'\n\nexport type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never\nexport type ReturnType<T> = T extends (...args: any) => infer R ? R : never\n\nexport interface RPCOptionsBasic extends Pipe {\n /** No return values expected */\n onlyEvents?: boolean\n /** Maximum timeout for waiting for response, in milliseconds */\n timeout?: number\n /** Custom logger */\n log?: LoggerInterface\n /** Custom error handler */\n onError?: (error: Error, functionName: string, args: any[]) => boolean | void\n /** Custom error handler for timeouts */\n onTimeoutError?: (functionName: string, args: any[]) => boolean | void\n /** Throw execptions. Default: true */\n exceptions?: boolean\n /** */\n stringHashPool?: UseStringHashPool\n}\n\nexport interface RPCOptions<Remote> extends RPCOptionsBasic {\n // /** No return values expected */\n // onlyEvents?: boolean\n /** Names of remote functions that do not need response. */\n eventNames?: (keyof Remote)[]\n}\n\nexport interface RPCFn<T> {\n /** Call the remote function and wait for the result. */\n (...args: ArgumentsType<T>): Promise<Awaited<ReturnType<T>>>\n /** Send event without asking for response */\n asEvent: (...args: ArgumentsType<T>) => void\n}\n\nexport type RPCReturn<RemoteFunctions> = {\n [K in keyof RemoteFunctions]: RPCFn<RemoteFunctions[K]>\n}\n\nlet rpcCounter = 1\n\nexport enum RPCMode {\n request = 1,\n event = 2,\n resolve = 3,\n reject = 4,\n}\n\nexport type RPCMessage = [\n mode: RPCMode,\n id: number,\n method: string | number | any,\n ...any,\n]\n\nconst defaultSerialize = (i: any) => i\nconst defaultDeserialize = defaultSerialize\n\nfunction setupRPCBasic(options: RPCOptionsBasic, functions: Record<string, (...args: any) => Promise<any>>, eventNames: string[] = []) {\n const {\n log,\n post,\n on,\n serialize = defaultSerialize,\n deserialize = defaultDeserialize,\n timeout = 60e3,\n onError,\n onTimeoutError,\n onlyEvents = false,\n exceptions = true,\n stringHashPool,\n } = options\n\n if (stringHashPool) {\n Object.keys(functions).forEach(stringHashPool.hash)\n }\n\n function checkEventNames(eventNames: string[]) {\n // eventNames.forEach((n) => {\n // if (functions[n] == null)\n // throw new Error(`event name ${n} has no registered function`)\n // })\n }\n\n checkEventNames(eventNames)\n\n function registerFunctions(additionalFunctions: any) {\n Object.assign(functions, additionalFunctions ?? {})\n if (stringHashPool)\n Object.keys(additionalFunctions).forEach(stringHashPool.hash)\n }\n\n function registerEventNames(additionalEventNames: string[]) {\n checkEventNames(additionalEventNames)\n eventNames.push(...additionalEventNames)\n }\n\n const rpcPromiseMap = new Map<number, {\n resolve: (...args: any) => any\n reject: (...args: any) => any\n timeoutId: Parameters<typeof clearTimeout>[0]\n }>()\n\n on(async (data) => {\n try {\n const msg = await deserialize(data) as RPCMessage\n const mode = msg?.[0]\n const id = mode === RPCMode.event ? 0 : msg?.[1]\n const [method, ...args] = msg.slice(mode === RPCMode.event ? 1 : 2)\n const methodName = stringHashPool?.stringForHash(method) ?? method\n if (mode === RPCMode.request || mode === RPCMode.event) {\n let result, error: any\n if (method != null) {\n try {\n const fn = functions[methodName]\n result = await fn(...args)\n }\n catch (e) {\n error = String(e)\n }\n }\n else {\n error = 'Method implementation missing'\n }\n if (error) {\n log?.warn('error', msg, error)\n onError?.(error, method ?? '', args)\n }\n if (id > 0) {\n const data = await serialize(error\n ? [RPCMode.reject, id, error]\n : [RPCMode.resolve, id, result])\n await post(data)\n }\n }\n else if (id) {\n const promise = rpcPromiseMap.get(id)\n if (promise != null) {\n clearTimeout(promise.timeoutId)\n if (mode === RPCMode.reject && exceptions === true)\n promise.reject(method)\n else\n promise.resolve(method)\n }\n rpcPromiseMap.delete(id)\n }\n }\n catch (err) {\n log?.warn('Error on handling RPC data. Invalid?', err, data)\n }\n })\n\n const proxyHandler = {\n get(_: any, methodName: string) {\n const method = stringHashPool?.hash(methodName) ?? methodName\n const sendEvent = async (...args: any[]) => await post(await serialize([RPCMode.event, method, ...args]))\n\n if (onlyEvents || eventNames.includes(methodName)) {\n sendEvent.asEvent = sendEvent\n return sendEvent\n }\n\n const sendCall = async (...args: any[]) => {\n const [promise, resolve, reject] = createPromise()\n const id = rpcCounter++\n\n let timeoutId: any\n if (timeout >= 0) {\n timeoutId = setTimeout(() => {\n try {\n // Custom onTimeoutError handler can throw its own error too\n onTimeoutError?.(methodName, args)\n throw new Error(`rpc timeout on calling \"${methodName}\"`)\n }\n catch (e) {\n if (exceptions === true)\n reject(e)\n else\n resolve(undefined)\n }\n rpcPromiseMap.delete(id)\n\n // Garbage Collection https://jakearchibald.com/2024/garbage-collection-and-closures/\n clearTimeout(timeoutId)\n timeoutId = undefined\n }, timeout).unref?.()\n }\n\n rpcPromiseMap.set(id, { resolve, reject, timeoutId })\n const data = await serialize([RPCMode.request, id, method, ...args])\n await post(data)\n return promise\n }\n sendCall.asEvent = sendEvent\n return sendCall\n },\n }\n\n return {\n post,\n serialize,\n rpcPromiseMap,\n proxyHandler,\n registerFunctions,\n registerEventNames,\n }\n}\n\nexport function useRPC<LocalFunctions, RemoteFunctions = LocalFunctions>(\n functions: LocalFunctions,\n options: RPCOptions<RemoteFunctions>,\n): RPCReturn<RemoteFunctions> {\n const { eventNames = [] } = options\n\n const { proxyHandler } = setupRPCBasic(options, functions as any, eventNames as any)\n\n return new Proxy({}, proxyHandler)\n}\n\nexport function useRPCHub(options: RPCOptionsBasic) {\n const eventNames: string[] = []\n const functions: Record<string, any> = {}\n\n const {\n proxyHandler,\n registerFunctions,\n registerEventNames,\n } = setupRPCBasic(options, functions, eventNames)\n\n function createRPCProxy() {\n return new Proxy({}, proxyHandler)\n }\n\n return function<LocalFunctions, RemoteFunctions = LocalFunctions>(\n additionalFunctions?: LocalFunctions,\n additionalEventNames: string[] = [],\n ): RPCReturn<RemoteFunctions> {\n registerFunctions(additionalFunctions ?? {})\n registerEventNames(additionalEventNames)\n return createRPCProxy()\n }\n}\n\nexport type UseRPCHubType = ReturnType<typeof useRPCHub>\n\n// Syntax test case\n// async function _demo() {\n// const hub: UseRPCHubType = {} as any\n// const x = hub({\n// test(name: string): string {\n// return name\n// },\n// })\n// await x.test('dsd')\n// }\n"],"mappings":";;;AA6CA,IAAI,aAAa;AAEjB,IAAY,UAAL;AACL;AACA;AACA;AACA;;KACD;AASD,MAAM,oBAAoB,MAAW;AACrC,MAAM,qBAAqB;AAE3B,SAAS,cAAc,SAA0B,WAA2D,aAAuB,EAAE,EAAE;CACrI,MAAM,EACJ,KACA,MACA,IACA,YAAY,kBACZ,cAAc,oBACd,UAAU,KACV,SACA,gBACA,aAAa,OACb,aAAa,MACb,mBACE;AAEJ,KAAI,eACF,QAAO,KAAK,UAAU,CAAC,QAAQ,eAAe,KAAK;CAGrD,SAAS,gBAAgB,YAAsB;AAO/C,iBAAgB,WAAW;CAE3B,SAAS,kBAAkB,qBAA0B;AACnD,SAAO,OAAO,WAAW,uBAAuB,EAAE,CAAC;AACnD,MAAI,eACF,QAAO,KAAK,oBAAoB,CAAC,QAAQ,eAAe,KAAK;;CAGjE,SAAS,mBA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G,OAAI,cAAc,WAAW,SAAS,WAAW,EAAE;AACjD,cAAU,UAAU;AACpB,WAAO;;GAGT,MAAM,WAAW,OAAO,GAAG,SAAgB;IACzC,MAAM,CAAC,SAAS,SAAS,UAAU,eAAe;IAClD,MAAM,KAAK;IAEX,IAAI;AACJ,QAAI,WAAW,EACb,aAAY,iBAAiB;AAC3B,SAAI;AAEF,uBAAiB,YAAY,KAAK;AAClC,YAAM,IAAI,MAAM,2BAA2B,WAAW,GAAG;cAEpD,GAAG;AACR,UAAI,eAAe,KACjB,QAAO,EAAE;UAET,SAAQ,OAAU;;AAEtB,mBAAc,OAAO,GAAG;AAGxB,kBAAa,UAAU;AACvB,iBAAY;OACX,QAAQ,CAAC,SAAS;AAGvB,kBAAc,IAAI,IAAI;KAAE;KAAS;KAAQ;KAAW,CAAC;AAErD,UAAM,KADO,MAAM,UAAU;;KAAkB;KAAI;KAAQ,GAAG;KAAK,CAAC,CACpD;AAChB,WAAO;;AAET,YAAS,UAAU;AACnB,UAAO;KAEV;EAOC;EACA;EACD;;AAGH,SAAgB,OACd,WACA,SAC4B;CAC5B,MAAM,EAAE,aAAa,EAAE,KAAK;CAE5B,MAAM,EAAE,iBAAiB,cAAc,SAAS,WAAkB,WAAkB;AAEpF,QAAO,IAAI,MAAM,EAAE,EAAE,aAAa;;AAGpC,SAAgB,UAAU,SAA0B;CAIlD,MAAM,EACJ,cACA,mBACA,uBACE,cAAc,SANqB,EAAE,EADZ,EAAE,CAOkB;CAEjD,SAAS,iBAAiB;AACxB,SAAO,IAAI,MAAM,EAAE,EAAE,aAAa;;AAGpC,QAAO,SACL,qBACA,uBAAiC,EAAE,EACP;AAC5B,oBAAkB,uBAAuB,EAAE,CAAC;AAC5C,qBAAmB,qBAAqB;AACxC,SAAO,gBAAgB"}
|
|
@@ -1,46 +1,55 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_common_data_is = require('../data/is.cjs');
|
|
3
|
-
const require_common_data_object = require('../data/object.cjs');
|
|
4
3
|
|
|
5
4
|
//#region src/common/schema/export-json-schema.ts
|
|
6
|
-
const
|
|
5
|
+
const _primitiveMap = {
|
|
7
6
|
string: "string",
|
|
8
7
|
number: "number",
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
int: "integer",
|
|
9
|
+
boolean: "boolean"
|
|
11
10
|
};
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
function transformSchema(schema) {
|
|
12
|
+
const out = {};
|
|
13
|
+
if (schema._enumValues) {
|
|
14
|
+
out.type = _primitiveMap[schema.type] ?? schema.type;
|
|
15
|
+
out.enum = [...schema._enumValues];
|
|
16
|
+
} else if (schema.type === "literal") out.const = schema._default;
|
|
17
|
+
else if (schema.type === "union" && Array.isArray(schema._union)) out.anyOf = schema._union.map((s) => transformSchema(s));
|
|
18
|
+
else if (schema.type === "object" && schema._object) {
|
|
19
|
+
out.type = "object";
|
|
15
20
|
const properties = {};
|
|
16
21
|
const required = [];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
22
|
+
for (const key of Object.keys(schema._object)) {
|
|
23
|
+
const propSchema = schema._object[key];
|
|
24
|
+
properties[key] = transformSchema(propSchema);
|
|
25
|
+
if (propSchema._optional !== true) required.push(key);
|
|
26
|
+
}
|
|
27
|
+
if (!require_common_data_is.isEmpty(properties)) out.properties = properties;
|
|
28
|
+
out.additionalProperties = false;
|
|
29
|
+
if (required.length > 0) out.required = required;
|
|
30
|
+
} else if (schema.type === "record" && schema._type) {
|
|
31
|
+
out.type = "object";
|
|
32
|
+
out.additionalProperties = transformSchema(schema._type);
|
|
33
|
+
} else if (schema.type === "array" && schema._type) {
|
|
34
|
+
out.type = "array";
|
|
35
|
+
out.items = transformSchema(schema._type);
|
|
36
|
+
} else if (schema.type === "tuple" && Array.isArray(schema._type)) {
|
|
37
|
+
out.type = "array";
|
|
38
|
+
out.items = schema._type.map((s) => transformSchema(s));
|
|
39
|
+
out.minItems = schema._type.length;
|
|
40
|
+
out.maxItems = schema._type.length;
|
|
41
|
+
} else if (schema.type === "none") out.type = "null";
|
|
42
|
+
else if (schema.type === "any") {} else {
|
|
43
|
+
const t = _primitiveMap[schema.type];
|
|
44
|
+
if (t) out.type = t;
|
|
40
45
|
}
|
|
46
|
+
if (schema._default !== void 0 && schema.type !== "literal") out.default = schema._default;
|
|
47
|
+
if (schema._meta?.desc) out.description = schema._meta.desc;
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
function schemaExportJsonSchema(schema) {
|
|
41
51
|
return {
|
|
42
52
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
43
|
-
additionalProperties: false,
|
|
44
53
|
...transformSchema(schema)
|
|
45
54
|
};
|
|
46
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export-json-schema.cjs","names":["isEmpty"],"sources":["../../../src/common/schema/export-json-schema.ts"],"sourcesContent":["import type { Type } from './schema'\nimport { isEmpty } from '../data'\
|
|
1
|
+
{"version":3,"file":"export-json-schema.cjs","names":["isEmpty"],"sources":["../../../src/common/schema/export-json-schema.ts"],"sourcesContent":["import type { Type } from './schema'\nimport { isEmpty } from '../data'\n\nconst _primitiveMap: Record<string, string> = {\n string: 'string',\n number: 'number',\n int: 'integer',\n boolean: 'boolean',\n}\n\nfunction transformSchema(schema: Type<any>): Record<string, any> {\n const out: Record<string, any> = {}\n\n if (schema._enumValues) {\n out.type = _primitiveMap[schema.type] ?? schema.type\n out.enum = [...schema._enumValues]\n }\n else if (schema.type === 'literal') {\n out.const = schema._default\n }\n else if (schema.type === 'union' && Array.isArray(schema._union)) {\n out.anyOf = schema._union.map((s: Type<any>) => transformSchema(s))\n }\n else if (schema.type === 'object' && schema._object) {\n out.type = 'object'\n const properties: Record<string, any> = {}\n const required: string[] = []\n for (const key of Object.keys(schema._object)) {\n const propSchema = schema._object[key] as Type<any>\n properties[key] = transformSchema(propSchema)\n if (propSchema._optional !== true)\n required.push(key)\n }\n if (!isEmpty(properties))\n out.properties = properties\n out.additionalProperties = false\n if (required.length > 0)\n out.required = required\n }\n else if (schema.type === 'record' && schema._type) {\n out.type = 'object'\n out.additionalProperties = transformSchema(schema._type)\n }\n else if (schema.type === 'array' && schema._type) {\n out.type = 'array'\n out.items = transformSchema(schema._type)\n }\n else if (schema.type === 'tuple' && Array.isArray(schema._type)) {\n out.type = 'array'\n out.items = (schema._type as Type<any>[]).map(s => transformSchema(s))\n out.minItems = schema._type.length\n out.maxItems = schema._type.length\n }\n else if (schema.type === 'none') {\n out.type = 'null'\n }\n else if (schema.type === 'any') {\n // no constraint\n }\n else {\n const t = _primitiveMap[schema.type]\n if (t)\n out.type = t\n }\n\n if (schema._default !== undefined && schema.type !== 'literal')\n out.default = schema._default\n if (schema._meta?.desc)\n out.description = schema._meta.desc\n\n return out\n}\n\nexport function schemaExportJsonSchema<T>(schema: Type<T>): Record<string, any> {\n return {\n $schema: 'http://json-schema.org/draft-07/schema#',\n ...transformSchema(schema),\n }\n}\n\nexport function schemaExportJsonSchemaString<T>(schema: Type<T>): string {\n const jsonSchema = schemaExportJsonSchema(schema)\n return JSON.stringify(jsonSchema, null, 2)\n}\n"],"mappings":";;;;AAGA,MAAM,gBAAwC;CAC5C,QAAQ;CACR,QAAQ;CACR,KAAK;CACL,SAAS;CACV;AAED,SAAS,gBAAgB,QAAwC;CAC/D,MAAM,MAA2B,EAAE;AAEnC,KAAI,OAAO,aAAa;AACtB,MAAI,OAAO,cAAc,OAAO,SAAS,OAAO;AAChD,MAAI,OAAO,CAAC,GAAG,OAAO,YAAY;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C;AAC9E,QAAO;EACL,SAAS;EACT,GAAG,gBAAgB,OAAO;EAC3B;;AAGH,SAAgB,6BAAgC,QAAyB;CACvE,MAAM,aAAa,uBAAuB,OAAO;AACjD,QAAO,KAAK,UAAU,YAAY,MAAM,EAAE"}
|
|
@@ -1,45 +1,54 @@
|
|
|
1
1
|
import { isEmpty } from "../data/is.mjs";
|
|
2
|
-
import { objectMap } from "../data/object.mjs";
|
|
3
2
|
|
|
4
3
|
//#region src/common/schema/export-json-schema.ts
|
|
5
|
-
const
|
|
4
|
+
const _primitiveMap = {
|
|
6
5
|
string: "string",
|
|
7
6
|
number: "number",
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
int: "integer",
|
|
8
|
+
boolean: "boolean"
|
|
10
9
|
};
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
function transformSchema(schema) {
|
|
11
|
+
const out = {};
|
|
12
|
+
if (schema._enumValues) {
|
|
13
|
+
out.type = _primitiveMap[schema.type] ?? schema.type;
|
|
14
|
+
out.enum = [...schema._enumValues];
|
|
15
|
+
} else if (schema.type === "literal") out.const = schema._default;
|
|
16
|
+
else if (schema.type === "union" && Array.isArray(schema._union)) out.anyOf = schema._union.map((s) => transformSchema(s));
|
|
17
|
+
else if (schema.type === "object" && schema._object) {
|
|
18
|
+
out.type = "object";
|
|
14
19
|
const properties = {};
|
|
15
20
|
const required = [];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
21
|
+
for (const key of Object.keys(schema._object)) {
|
|
22
|
+
const propSchema = schema._object[key];
|
|
23
|
+
properties[key] = transformSchema(propSchema);
|
|
24
|
+
if (propSchema._optional !== true) required.push(key);
|
|
25
|
+
}
|
|
26
|
+
if (!isEmpty(properties)) out.properties = properties;
|
|
27
|
+
out.additionalProperties = false;
|
|
28
|
+
if (required.length > 0) out.required = required;
|
|
29
|
+
} else if (schema.type === "record" && schema._type) {
|
|
30
|
+
out.type = "object";
|
|
31
|
+
out.additionalProperties = transformSchema(schema._type);
|
|
32
|
+
} else if (schema.type === "array" && schema._type) {
|
|
33
|
+
out.type = "array";
|
|
34
|
+
out.items = transformSchema(schema._type);
|
|
35
|
+
} else if (schema.type === "tuple" && Array.isArray(schema._type)) {
|
|
36
|
+
out.type = "array";
|
|
37
|
+
out.items = schema._type.map((s) => transformSchema(s));
|
|
38
|
+
out.minItems = schema._type.length;
|
|
39
|
+
out.maxItems = schema._type.length;
|
|
40
|
+
} else if (schema.type === "none") out.type = "null";
|
|
41
|
+
else if (schema.type === "any") {} else {
|
|
42
|
+
const t = _primitiveMap[schema.type];
|
|
43
|
+
if (t) out.type = t;
|
|
39
44
|
}
|
|
45
|
+
if (schema._default !== void 0 && schema.type !== "literal") out.default = schema._default;
|
|
46
|
+
if (schema._meta?.desc) out.description = schema._meta.desc;
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
function schemaExportJsonSchema(schema) {
|
|
40
50
|
return {
|
|
41
51
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
42
|
-
additionalProperties: false,
|
|
43
52
|
...transformSchema(schema)
|
|
44
53
|
};
|
|
45
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export-json-schema.mjs","names":[],"sources":["../../../src/common/schema/export-json-schema.ts"],"sourcesContent":["import type { Type } from './schema'\nimport { isEmpty } from '../data'\
|
|
1
|
+
{"version":3,"file":"export-json-schema.mjs","names":[],"sources":["../../../src/common/schema/export-json-schema.ts"],"sourcesContent":["import type { Type } from './schema'\nimport { isEmpty } from '../data'\n\nconst _primitiveMap: Record<string, string> = {\n string: 'string',\n number: 'number',\n int: 'integer',\n boolean: 'boolean',\n}\n\nfunction transformSchema(schema: Type<any>): Record<string, any> {\n const out: Record<string, any> = {}\n\n if (schema._enumValues) {\n out.type = _primitiveMap[schema.type] ?? schema.type\n out.enum = [...schema._enumValues]\n }\n else if (schema.type === 'literal') {\n out.const = schema._default\n }\n else if (schema.type === 'union' && Array.isArray(schema._union)) {\n out.anyOf = schema._union.map((s: Type<any>) => transformSchema(s))\n }\n else if (schema.type === 'object' && schema._object) {\n out.type = 'object'\n const properties: Record<string, any> = {}\n const required: string[] = []\n for (const key of Object.keys(schema._object)) {\n const propSchema = schema._object[key] as Type<any>\n properties[key] = transformSchema(propSchema)\n if (propSchema._optional !== true)\n required.push(key)\n }\n if (!isEmpty(properties))\n out.properties = properties\n out.additionalProperties = false\n if (required.length > 0)\n out.required = required\n }\n else if (schema.type === 'record' && schema._type) {\n out.type = 'object'\n out.additionalProperties = transformSchema(schema._type)\n }\n else if (schema.type === 'array' && schema._type) {\n out.type = 'array'\n out.items = transformSchema(schema._type)\n }\n else if (schema.type === 'tuple' && Array.isArray(schema._type)) {\n out.type = 'array'\n out.items = (schema._type as Type<any>[]).map(s => transformSchema(s))\n out.minItems = schema._type.length\n out.maxItems = schema._type.length\n }\n else if (schema.type === 'none') {\n out.type = 'null'\n }\n else if (schema.type === 'any') {\n // no constraint\n }\n else {\n const t = _primitiveMap[schema.type]\n if (t)\n out.type = t\n }\n\n if (schema._default !== undefined && schema.type !== 'literal')\n out.default = schema._default\n if (schema._meta?.desc)\n out.description = schema._meta.desc\n\n return out\n}\n\nexport function schemaExportJsonSchema<T>(schema: Type<T>): Record<string, any> {\n return {\n $schema: 'http://json-schema.org/draft-07/schema#',\n ...transformSchema(schema),\n }\n}\n\nexport function schemaExportJsonSchemaString<T>(schema: Type<T>): string {\n const jsonSchema = schemaExportJsonSchema(schema)\n return JSON.stringify(jsonSchema, null, 2)\n}\n"],"mappings":";;;AAGA,MAAM,gBAAwC;CAC5C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AI,cAAc,OAAO;AAC/B,MAAI,EACF,KAAI,OAAO;;AAGf,KAAI,OAAO,aAAa,UAAa,OAAO,SAAS,UACnD,KAAI,UAAU,OAAO;AACvB,KAAI,OAAO,OAAO,KAChB,KAAI,cAAc,OAAO,MAAM;AAEjC,QAAO;;AAGT,SAAgB,uBAA0B,QAAsC;AAC9E,QAAO;EACL,SAAS;EACT,GAAG,gBAAgB,OAAO;EAC3B;;AAGH,SAAgB,6BAAgC,QAAyB;CACvE,MAAM,aAAa,uBAAuB,OAAO;AACjD,QAAO,KAAK,UAAU,YAAY,MAAM,EAAE"}
|
|
@@ -8,27 +8,44 @@ const require_common_schema_parse_args = require('./parse-args.cjs');
|
|
|
8
8
|
const require_common_schema_parse_env = require('./parse-env.cjs');
|
|
9
9
|
const require_common_schema_schema = require('./schema.cjs');
|
|
10
10
|
const require_common_schema_serialize = require('./serialize.cjs');
|
|
11
|
+
const require_common_schema_sql_table = require('./sql/table.cjs');
|
|
12
|
+
const require_common_schema_sql_expr = require('./sql/expr.cjs');
|
|
13
|
+
const require_common_schema_sql_select = require('./sql/select.cjs');
|
|
11
14
|
const require_common_schema_z_collection = require('./z-collection.cjs');
|
|
12
15
|
|
|
16
|
+
exports.SelectBuilder = require_common_schema_sql_select.SelectBuilder;
|
|
13
17
|
exports.Type = require_common_schema_schema.Type;
|
|
18
|
+
exports.and = require_common_schema_sql_expr.and;
|
|
14
19
|
exports.any = require_common_schema_schema.any;
|
|
15
20
|
exports.array = require_common_schema_schema.array;
|
|
16
21
|
exports.boolean = require_common_schema_schema.boolean;
|
|
17
22
|
exports.deserializeSchema = require_common_schema_serialize.deserializeSchema;
|
|
18
23
|
exports.double = require_common_schema_schema.double;
|
|
24
|
+
exports.eq = require_common_schema_sql_expr.eq;
|
|
19
25
|
exports.float = require_common_schema_schema.float;
|
|
26
|
+
exports.from = require_common_schema_sql_select.from;
|
|
20
27
|
exports.func = require_common_schema_schema.func;
|
|
28
|
+
exports.gt = require_common_schema_sql_expr.gt;
|
|
29
|
+
exports.gte = require_common_schema_sql_expr.gte;
|
|
21
30
|
exports.helpSchemaArgs = require_common_schema_parse_args.helpSchemaArgs;
|
|
31
|
+
exports.inArray = require_common_schema_sql_expr.inArray;
|
|
22
32
|
exports.int = require_common_schema_schema.int;
|
|
33
|
+
exports.isColumn = require_common_schema_sql_table.isColumn;
|
|
23
34
|
exports.isSchemaDefault = require_common_schema_utils.isSchemaDefault;
|
|
24
35
|
exports.isSchemaObject = require_common_schema_utils.isSchemaObject;
|
|
25
36
|
exports.isSchemaObjectFlat = require_common_schema_utils.isSchemaObjectFlat;
|
|
26
37
|
exports.isSchemaOptional = require_common_schema_utils.isSchemaOptional;
|
|
27
38
|
exports.isSchemaPrimitive = require_common_schema_utils.isSchemaPrimitive;
|
|
39
|
+
exports.like = require_common_schema_sql_expr.like;
|
|
28
40
|
exports.literal = require_common_schema_schema.literal;
|
|
41
|
+
exports.lt = require_common_schema_sql_expr.lt;
|
|
42
|
+
exports.lte = require_common_schema_sql_expr.lte;
|
|
43
|
+
exports.ne = require_common_schema_sql_expr.ne;
|
|
29
44
|
exports.none = require_common_schema_schema.none;
|
|
45
|
+
exports.not = require_common_schema_sql_expr.not;
|
|
30
46
|
exports.number = require_common_schema_schema.number;
|
|
31
47
|
exports.object = require_common_schema_schema.object;
|
|
48
|
+
exports.or = require_common_schema_sql_expr.or;
|
|
32
49
|
exports.parseSchemaArgs = require_common_schema_parse_args.parseSchemaArgs;
|
|
33
50
|
exports.parseSchemaEnv = require_common_schema_parse_env.parseSchemaEnv;
|
|
34
51
|
exports.real = require_common_schema_schema.real;
|
|
@@ -41,10 +58,14 @@ exports.schemaExportSwiftStruct = require_common_schema_export_swift.schemaExpor
|
|
|
41
58
|
exports.schemaExportTypescriptInterface = require_common_schema_export_typescript.schemaExportTypescriptInterface;
|
|
42
59
|
exports.schemaParseObject = require_common_schema_parse_object.schemaParseObject;
|
|
43
60
|
exports.schemaValidateObject = require_common_schema_parse_object.schemaValidateObject;
|
|
61
|
+
exports.select = require_common_schema_sql_select.select;
|
|
44
62
|
exports.serializeSchema = require_common_schema_serialize.serializeSchema;
|
|
63
|
+
exports.sqlIsNotNull = require_common_schema_sql_expr.sqlIsNotNull;
|
|
64
|
+
exports.sqlIsNull = require_common_schema_sql_expr.sqlIsNull;
|
|
45
65
|
exports.string = require_common_schema_schema.string;
|
|
46
66
|
exports.stringFromSchemaEnv = require_common_schema_parse_env.stringFromSchemaEnv;
|
|
47
67
|
exports.stringLiterals = require_common_schema_schema.stringLiterals;
|
|
68
|
+
exports.table = require_common_schema_sql_table.table;
|
|
48
69
|
exports.tuple = require_common_schema_schema.tuple;
|
|
49
70
|
exports.union = require_common_schema_schema.union;
|
|
50
71
|
Object.defineProperty(exports, 'z', {
|
|
@@ -8,6 +8,9 @@ import { i as stringFromSchemaEnv, n as SchemaEnvType, r as parseSchemaEnv, t as
|
|
|
8
8
|
import { i as schemaValidateObject, n as schemaCreateObject, r as schemaParseObject, t as SchemaValidateMessage } from "../../parse-object-D_fCDXxd.cjs";
|
|
9
9
|
import { t as StandardSchemaV1 } from "../../schema-standard-BxRHxZeM.cjs";
|
|
10
10
|
import { n as deserializeSchema, r as serializeSchema, t as SerializedType } from "../../serialize-9GhlcFMv.cjs";
|
|
11
|
-
import { n as
|
|
12
|
-
import { a as
|
|
13
|
-
|
|
11
|
+
import { a as table, i as isColumn, n as TableColumns, r as TableShape, t as Column } from "../../table-IkLXirT-.cjs";
|
|
12
|
+
import { a as gte, c as lt, d as not, f as or, i as gt, l as lte, m as sqlIsNull, n as and, o as inArray, p as sqlIsNotNull, r as eq, s as like, t as Expr, u as ne } from "../../expr-yYgSeBZ3.cjs";
|
|
13
|
+
import { a as RowFromTable, c as select, i as RowFromSelection, n as InferRow, o as SelectBuilder, r as QueryDependencies, s as from, t as CompiledQuery } from "../../select-DrciHdk_.cjs";
|
|
14
|
+
import { n as IsEqual, t as Expect } from "../../type-test-CBK-iJ9d.cjs";
|
|
15
|
+
import { a as isSchemaPrimitive, i as isSchemaOptional, n as isSchemaObject, r as isSchemaObjectFlat, t as isSchemaDefault } from "../../utils-nCQklGHV.cjs";
|
|
16
|
+
export { Column, CompiledQuery, Expect, Expr, Infer, InferRow, IsEqual, QueryDependencies, RowFromSelection, RowFromTable, SchemaEnvOptions, SchemaEnvType, SchemaValidateMessage, SelectBuilder, SerializedType, StandardSchemaV1, TableColumns, TableShape, Type, TypeArray, TypeArrayOutput, TypeLiterals, TypeMeta, TypeObjectFixOptional, TypeTuple, TypeUnion, and, any, array, boolean, deserializeSchema, double, eq, float, from, func, gt, gte, helpSchemaArgs, inArray, int, isColumn, isSchemaDefault, isSchemaObject, isSchemaObjectFlat, isSchemaOptional, isSchemaPrimitive, like, literal, lt, lte, ne, none, not, number, object, or, parseSchemaArgs, parseSchemaEnv, real, record, rpc, schemaCreateObject, schemaExportJsonSchema, schemaExportJsonSchemaString, schemaExportSwiftStruct, schemaExportTypescriptInterface, schemaParseObject, schemaValidateObject, select, serializeSchema, sqlIsNotNull, sqlIsNull, string, stringFromSchemaEnv, stringLiterals, table, tuple, union, z_collection_d_exports as z };
|
|
@@ -7,7 +7,10 @@ import { i as stringFromSchemaEnv, n as SchemaEnvType, r as parseSchemaEnv, t as
|
|
|
7
7
|
import { i as schemaValidateObject, n as schemaCreateObject, r as schemaParseObject, t as SchemaValidateMessage } from "../../parse-object-BRWSD2uh.mjs";
|
|
8
8
|
import { t as StandardSchemaV1 } from "../../schema-standard-Q-bdIO6s.mjs";
|
|
9
9
|
import { n as deserializeSchema, r as serializeSchema, t as SerializedType } from "../../serialize-rRk9F-zH.mjs";
|
|
10
|
-
import { n as
|
|
11
|
-
import { a as
|
|
12
|
-
import { t as
|
|
13
|
-
|
|
10
|
+
import { a as table, i as isColumn, n as TableColumns, r as TableShape, t as Column } from "../../table-Cr8tjDIL.mjs";
|
|
11
|
+
import { a as gte, c as lt, d as not, f as or, i as gt, l as lte, m as sqlIsNull, n as and, o as inArray, p as sqlIsNotNull, r as eq, s as like, t as Expr, u as ne } from "../../expr-CCKrqOw1.mjs";
|
|
12
|
+
import { a as RowFromTable, c as select, i as RowFromSelection, n as InferRow, o as SelectBuilder, r as QueryDependencies, s as from, t as CompiledQuery } from "../../select-F2KpP6mo.mjs";
|
|
13
|
+
import { n as IsEqual, t as Expect } from "../../type-test-BvzWDJz3.mjs";
|
|
14
|
+
import { a as isSchemaPrimitive, i as isSchemaOptional, n as isSchemaObject, r as isSchemaObjectFlat, t as isSchemaDefault } from "../../utils-1RyCGkpQ.mjs";
|
|
15
|
+
import { t as z_collection_d_exports } from "../../z-collection-BSfgRU0Q.mjs";
|
|
16
|
+
export { Column, CompiledQuery, Expect, Expr, Infer, InferRow, IsEqual, QueryDependencies, RowFromSelection, RowFromTable, SchemaEnvOptions, SchemaEnvType, SchemaValidateMessage, SelectBuilder, SerializedType, StandardSchemaV1, TableColumns, TableShape, Type, TypeArray, TypeArrayOutput, TypeLiterals, TypeMeta, TypeObjectFixOptional, TypeTuple, TypeUnion, and, any, array, boolean, deserializeSchema, double, eq, float, from, func, gt, gte, helpSchemaArgs, inArray, int, isColumn, isSchemaDefault, isSchemaObject, isSchemaObjectFlat, isSchemaOptional, isSchemaPrimitive, like, literal, lt, lte, ne, none, not, number, object, or, parseSchemaArgs, parseSchemaEnv, real, record, rpc, schemaCreateObject, schemaExportJsonSchema, schemaExportJsonSchemaString, schemaExportSwiftStruct, schemaExportTypescriptInterface, schemaParseObject, schemaValidateObject, select, serializeSchema, sqlIsNotNull, sqlIsNull, string, stringFromSchemaEnv, stringLiterals, table, tuple, union, z_collection_d_exports as z };
|
|
@@ -7,6 +7,9 @@ import { helpSchemaArgs, parseSchemaArgs } from "./parse-args.mjs";
|
|
|
7
7
|
import { parseSchemaEnv, stringFromSchemaEnv } from "./parse-env.mjs";
|
|
8
8
|
import { Type, any, array, boolean, double, float, func, int, literal, none, number, object, real, record, rpc, string, stringLiterals, tuple, union } from "./schema.mjs";
|
|
9
9
|
import { deserializeSchema, serializeSchema } from "./serialize.mjs";
|
|
10
|
+
import { isColumn, table } from "./sql/table.mjs";
|
|
11
|
+
import { and, eq, gt, gte, inArray, like, lt, lte, ne, not, or, sqlIsNotNull, sqlIsNull } from "./sql/expr.mjs";
|
|
12
|
+
import { SelectBuilder, from, select } from "./sql/select.mjs";
|
|
10
13
|
import { t as z_collection_exports } from "./z-collection.mjs";
|
|
11
14
|
|
|
12
|
-
export { Type, any, array, boolean, deserializeSchema, double, float, func, helpSchemaArgs, int, isSchemaDefault, isSchemaObject, isSchemaObjectFlat, isSchemaOptional, isSchemaPrimitive, literal, none, number, object, parseSchemaArgs, parseSchemaEnv, real, record, rpc, schemaCreateObject, schemaExportJsonSchema, schemaExportJsonSchemaString, schemaExportSwiftStruct, schemaExportTypescriptInterface, schemaParseObject, schemaValidateObject, serializeSchema, string, stringFromSchemaEnv, stringLiterals, tuple, union, z_collection_exports as z };
|
|
15
|
+
export { SelectBuilder, Type, and, any, array, boolean, deserializeSchema, double, eq, float, from, func, gt, gte, helpSchemaArgs, inArray, int, isColumn, isSchemaDefault, isSchemaObject, isSchemaObjectFlat, isSchemaOptional, isSchemaPrimitive, like, literal, lt, lte, ne, none, not, number, object, or, parseSchemaArgs, parseSchemaEnv, real, record, rpc, schemaCreateObject, schemaExportJsonSchema, schemaExportJsonSchemaString, schemaExportSwiftStruct, schemaExportTypescriptInterface, schemaParseObject, schemaValidateObject, select, serializeSchema, sqlIsNotNull, sqlIsNull, string, stringFromSchemaEnv, stringLiterals, table, tuple, union, z_collection_exports as z };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_common_schema_sql_table = require('./table.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/common/schema/sql/expr.ts
|
|
5
|
+
function operand(v) {
|
|
6
|
+
if (require_common_schema_sql_table.isColumn(v)) return {
|
|
7
|
+
kind: "expr",
|
|
8
|
+
sql: `"${v._table}"."${v._name}"`,
|
|
9
|
+
params: [],
|
|
10
|
+
refs: [v]
|
|
11
|
+
};
|
|
12
|
+
if (v && v.kind === "expr") return v;
|
|
13
|
+
return {
|
|
14
|
+
kind: "expr",
|
|
15
|
+
sql: "?",
|
|
16
|
+
params: [v],
|
|
17
|
+
refs: []
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function binop(op) {
|
|
21
|
+
return (a, b) => {
|
|
22
|
+
const x = operand(a);
|
|
23
|
+
const y = operand(b);
|
|
24
|
+
return {
|
|
25
|
+
kind: "expr",
|
|
26
|
+
sql: `${x.sql} ${op} ${y.sql}`,
|
|
27
|
+
params: [...x.params, ...y.params],
|
|
28
|
+
refs: [...x.refs, ...y.refs]
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const eq = binop("=");
|
|
33
|
+
const ne = binop("<>");
|
|
34
|
+
const gt = binop(">");
|
|
35
|
+
const gte = binop(">=");
|
|
36
|
+
const lt = binop("<");
|
|
37
|
+
const lte = binop("<=");
|
|
38
|
+
const like = binop("LIKE");
|
|
39
|
+
function and(...parts) {
|
|
40
|
+
const list = parts.filter((p) => !!p);
|
|
41
|
+
if (list.length === 0) return {
|
|
42
|
+
kind: "expr",
|
|
43
|
+
sql: "1=1",
|
|
44
|
+
params: [],
|
|
45
|
+
refs: []
|
|
46
|
+
};
|
|
47
|
+
if (list.length === 1) return list[0];
|
|
48
|
+
return {
|
|
49
|
+
kind: "expr",
|
|
50
|
+
sql: list.map((p) => `(${p.sql})`).join(" AND "),
|
|
51
|
+
params: list.flatMap((p) => p.params),
|
|
52
|
+
refs: list.flatMap((p) => p.refs)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function or(...parts) {
|
|
56
|
+
const list = parts.filter((p) => !!p);
|
|
57
|
+
if (list.length === 0) return {
|
|
58
|
+
kind: "expr",
|
|
59
|
+
sql: "1=0",
|
|
60
|
+
params: [],
|
|
61
|
+
refs: []
|
|
62
|
+
};
|
|
63
|
+
if (list.length === 1) return list[0];
|
|
64
|
+
return {
|
|
65
|
+
kind: "expr",
|
|
66
|
+
sql: list.map((p) => `(${p.sql})`).join(" OR "),
|
|
67
|
+
params: list.flatMap((p) => p.params),
|
|
68
|
+
refs: list.flatMap((p) => p.refs)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function not(e) {
|
|
72
|
+
return {
|
|
73
|
+
kind: "expr",
|
|
74
|
+
sql: `NOT (${e.sql})`,
|
|
75
|
+
params: e.params,
|
|
76
|
+
refs: e.refs
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function sqlIsNull(col) {
|
|
80
|
+
const x = operand(col);
|
|
81
|
+
return {
|
|
82
|
+
kind: "expr",
|
|
83
|
+
sql: `${x.sql} IS NULL`,
|
|
84
|
+
params: x.params,
|
|
85
|
+
refs: x.refs
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function sqlIsNotNull(col) {
|
|
89
|
+
const x = operand(col);
|
|
90
|
+
return {
|
|
91
|
+
kind: "expr",
|
|
92
|
+
sql: `${x.sql} IS NOT NULL`,
|
|
93
|
+
params: x.params,
|
|
94
|
+
refs: x.refs
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function inArray(col, values) {
|
|
98
|
+
const x = operand(col);
|
|
99
|
+
if (values.length === 0) return {
|
|
100
|
+
kind: "expr",
|
|
101
|
+
sql: "1=0",
|
|
102
|
+
params: [],
|
|
103
|
+
refs: x.refs
|
|
104
|
+
};
|
|
105
|
+
const placeholders = values.map(() => "?").join(", ");
|
|
106
|
+
return {
|
|
107
|
+
kind: "expr",
|
|
108
|
+
sql: `${x.sql} IN (${placeholders})`,
|
|
109
|
+
params: [...x.params, ...values],
|
|
110
|
+
refs: x.refs
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
exports.and = and;
|
|
116
|
+
exports.eq = eq;
|
|
117
|
+
exports.gt = gt;
|
|
118
|
+
exports.gte = gte;
|
|
119
|
+
exports.inArray = inArray;
|
|
120
|
+
exports.like = like;
|
|
121
|
+
exports.lt = lt;
|
|
122
|
+
exports.lte = lte;
|
|
123
|
+
exports.ne = ne;
|
|
124
|
+
exports.not = not;
|
|
125
|
+
exports.or = or;
|
|
126
|
+
exports.sqlIsNotNull = sqlIsNotNull;
|
|
127
|
+
exports.sqlIsNull = sqlIsNull;
|
|
128
|
+
//# sourceMappingURL=expr.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expr.cjs","names":["isColumn"],"sources":["../../../../src/common/schema/sql/expr.ts"],"sourcesContent":["import type { Column } from './table'\nimport { isColumn } from './table'\n\nexport interface Expr {\n readonly kind: 'expr'\n readonly sql: string\n readonly params: unknown[]\n readonly refs: Column[]\n}\n\nfunction operand(v: any): Expr {\n if (isColumn(v)) {\n return {\n kind: 'expr',\n sql: `\"${v._table}\".\"${v._name}\"`,\n params: [],\n refs: [v],\n }\n }\n if (v && v.kind === 'expr')\n return v as Expr\n return { kind: 'expr', sql: '?', params: [v], refs: [] }\n}\n\nfunction binop(op: string) {\n return (a: Column | Expr | unknown, b: Column | Expr | unknown): Expr => {\n const x = operand(a)\n const y = operand(b)\n return {\n kind: 'expr',\n sql: `${x.sql} ${op} ${y.sql}`,\n params: [...x.params, ...y.params],\n refs: [...x.refs, ...y.refs],\n }\n }\n}\n\nexport const eq = binop('=')\nexport const ne = binop('<>')\nexport const gt = binop('>')\nexport const gte = binop('>=')\nexport const lt = binop('<')\nexport const lte = binop('<=')\nexport const like = binop('LIKE')\n\nexport function and(...parts: (Expr | undefined | false | null)[]): Expr {\n const list = parts.filter((p): p is Expr => !!p)\n if (list.length === 0)\n return { kind: 'expr', sql: '1=1', params: [], refs: [] }\n if (list.length === 1)\n return list[0]\n return {\n kind: 'expr',\n sql: list.map(p => `(${p.sql})`).join(' AND '),\n params: list.flatMap(p => p.params),\n refs: list.flatMap(p => p.refs),\n }\n}\n\nexport function or(...parts: (Expr | undefined | false | null)[]): Expr {\n const list = parts.filter((p): p is Expr => !!p)\n if (list.length === 0)\n return { kind: 'expr', sql: '1=0', params: [], refs: [] }\n if (list.length === 1)\n return list[0]\n return {\n kind: 'expr',\n sql: list.map(p => `(${p.sql})`).join(' OR '),\n params: list.flatMap(p => p.params),\n refs: list.flatMap(p => p.refs),\n }\n}\n\nexport function not(e: Expr): Expr {\n return { kind: 'expr', sql: `NOT (${e.sql})`, params: e.params, refs: e.refs }\n}\n\nexport function sqlIsNull(col: Column | Expr): Expr {\n const x = operand(col)\n return { kind: 'expr', sql: `${x.sql} IS NULL`, params: x.params, refs: x.refs }\n}\n\nexport function sqlIsNotNull(col: Column | Expr): Expr {\n const x = operand(col)\n return { kind: 'expr', sql: `${x.sql} IS NOT NULL`, params: x.params, refs: x.refs }\n}\n\nexport function inArray(col: Column | Expr, values: unknown[]): Expr {\n const x = operand(col)\n if (values.length === 0)\n return { kind: 'expr', sql: '1=0', params: [], refs: x.refs }\n const placeholders = values.map(() => '?').join(', ')\n return {\n kind: 'expr',\n sql: `${x.sql} IN (${placeholders})`,\n params: [...x.params, ...values],\n refs: x.refs,\n }\n}\n"],"mappings":";;;;AAUA,SAAS,QAAQ,GAAc;AAC7B,KAAIA,yCAAS,EAAE,CACb,QAAO;EACL,MAAM;EACN,KAAK,IAAI,EAAE,OAAO,KAAK,EAAE,MAAM;EAC/B,QAAQ,EAAE;EACV,MAAM,CAAC,EAAE;EACV;AAEH,KAAI,KAAK,EAAE,SAAS,OAClB,QAAO;AACT,QAAO;EAAE,MAAM;EAAQ,KAAK;EAAK,QAAQ,CAAC,EAAE;EAAE,MAAM,EAAE;EAAE;;AAG1D,SAAS,MAAM,IAAY;AACzB,SAAQ,GAA4B,MAAqC;EACvE,MAAM,IAAI,QAAQ,EAAE;EACpB,MAAM,IAAI,QAAQ,EAAE;AACpB,SAAO;GACL,MAAM;GACN,KAAK,GAAG,EAAE,IAAI,GAAG,GAAG,GAAG,EAAE;GACz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MAAM;EAAQ,KAAK,QAAQ,EAAE,IAAI;EAAI,QAAQ,EAAE;EAAQ,MAAM,EAAE;EAAM;;AAGhF,SAAgB,UAAU,KAA0B;CAClD,MAAM,IAAI,QAAQ,IAAI;AACtB,QAAO;EAAE,MAAM;EAAQ,KAAK,GAAG,EAAE,IAAI;EAAW,QAAQ,EAAE;EAAQ,MAAM,EAAE;EAAM;;AAGlF,SAAgB,aAAa,KAA0B;CACrD,MAAM,IAAI,QAAQ,IAAI;AACtB,QAAO;EAAE,MAAM;EAAQ,KAAK,GAAG,EAAE,IAAI;EAAe,QAAQ,EAAE;EAAQ,MAAM,EAAE;EAAM;;AAGtF,SAAgB,QAAQ,KAAoB,QAAyB;CACnE,MAAM,IAAI,QAAQ,IAAI;AACtB,KAAI,OAAO,WAAW,EACpB,QAAO;EAAE,MAAM;EAAQ,KAAK;EAAO,QAAQ,EAAE;EAAE,MAAM,EAAE;EAAM;CAC/D,MAAM,eAAe,OAAO,UAAU,IAAI,CAAC,KAAK,KAAK;AACrD,QAAO;EACL,MAAM;EACN,KAAK,GAAG,EAAE,IAAI,OAAO,aAAa;EAClC,QAAQ,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO;EAChC,MAAM,EAAE;EACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as gte, c as lt, d as not, f as or, i as gt, l as lte, m as sqlIsNull, n as and, o as inArray, p as sqlIsNotNull, r as eq, s as like, t as Expr, u as ne } from "../../../expr-yYgSeBZ3.cjs";
|
|
2
|
+
export { Expr, and, eq, gt, gte, inArray, like, lt, lte, ne, not, or, sqlIsNotNull, sqlIsNull };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as gte, c as lt, d as not, f as or, i as gt, l as lte, m as sqlIsNull, n as and, o as inArray, p as sqlIsNotNull, r as eq, s as like, t as Expr, u as ne } from "../../../expr-CCKrqOw1.mjs";
|
|
2
|
+
export { Expr, and, eq, gt, gte, inArray, like, lt, lte, ne, not, or, sqlIsNotNull, sqlIsNull };
|