@junobuild/functions 0.0.10 → 0.0.11
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/README.md +1 -1
- package/hooks/schemas/collections.d.ts +2 -1
- package/index.js +1 -1
- package/index.js.map +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -569,7 +569,7 @@ Defines the collections where a hook or assertion should run.
|
|
|
569
569
|
| ------------- | ----------------------------------- |
|
|
570
570
|
| `Collections` | `z.infer<typeof CollectionsSchema>` |
|
|
571
571
|
|
|
572
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/collections.ts#
|
|
572
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/collections.ts#L19)
|
|
573
573
|
|
|
574
574
|
#### :gear: RawPrincipal
|
|
575
575
|
|
|
@@ -4,7 +4,8 @@ import * as z from 'zod';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const CollectionsSchema: z.ZodObject<{
|
|
6
6
|
/**
|
|
7
|
-
* An array
|
|
7
|
+
* An array of collection names where the hook or assertion will run.
|
|
8
|
+
* If empty, no hooks or assertions are triggered.
|
|
8
9
|
*/
|
|
9
10
|
collections: z.ZodReadonly<z.ZodArray<z.ZodString, "many">>;
|
|
10
11
|
}, "strict", z.ZodTypeAny, {
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as I,b as T,c as S,d as J,e as y,f as d,g as h,h as z,i as r}from"./chunk-LVVTFR6B.js";import{a as U,b as w,c as P}from"./chunk-CCKUQNB5.js";import*as i from"zod";import*as o from"zod";var n=o.object({collections:o.array(o.string()).
|
|
1
|
+
import{a as I,b as T,c as S,d as J,e as y,f as d,g as h,h as z,i as r}from"./chunk-LVVTFR6B.js";import{a as U,b as w,c as P}from"./chunk-CCKUQNB5.js";import*as i from"zod";import*as o from"zod";var n=o.object({collections:o.array(o.string()).readonly()}).strict();import*as t from"zod";var f=e=>t.object({caller:S,data:e}).strict(),A=e=>t.function().args(e).returns(t.void()),l=e=>t.function().args(e).returns(t.promise(t.void()).or(t.void()));import*as O from"zod";import*as s from"zod";var u=s.object({before:r.optional(),after:r}).strict(),j=s.object({data:z,description:h.optional(),version:T.optional()}).strict(),k=s.object({current:r.optional(),proposed:j}).strict();var D=e=>O.object({collection:y,key:d,data:e}).strict(),F=f(D(u)),H=f(D(k));import*as c from"zod";var p=c.record(c.unknown());var C=e=>n.extend({assert:A(e)}).strict(),Z=C(H),oe=Z,v=e=>i.function().args(p).returns(e),re=e=>i.union([e,v(e)]);function ne(e){return e}import*as m from"zod";var R=e=>n.extend({run:l(e)}).strict(),g=R(F),ae=g,_=e=>m.function().args(p).returns(e),xe=e=>m.union([e,_(e)]);function fe(e){return e}import{jsonReplacer as E}from"@dfinity/utils";var a=e=>{let b=e.map(x=>typeof x=="object"?JSON.stringify(x,E):x).join(" ");globalThis.__ic_cdk_print(b)};globalThis.console={info(...e){a(e)},log(...e){a(e)},warn(...e){a(e)},error(...e){a(e)}};export{re as AssertFnOrObjectSchema,v as AssertFnSchema,A as AssertFunctionSchema,oe as AssertSchema,H as AssertSetDocContextSchema,Z as AssertSetDocSchema,y as CollectionSchema,n as CollectionsSchema,k as DocAssertSetSchema,D as DocContextSchema,h as DocDescriptionSchema,r as DocSchema,u as DocUpsertSchema,f as HookContextSchema,xe as HookFnOrObjectSchema,_ as HookFnSchema,ae as HookSchema,d as KeySchema,F as OnSetDocContextSchema,g as OnSetDocSchema,P as PrincipalSchema,j as ProposedDocSchema,z as RawDataSchema,w as RawPrincipalSchema,S as RawUserIdSchema,l as RunFunctionSchema,p as SatelliteEnvSchema,I as TimestampSchema,U as Uint8ArraySchema,J as UserIdSchema,T as VersionSchema,ne as defineAssert,fe as defineHook};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/hooks/db/assertions.ts", "src/hooks/schemas/collections.ts", "src/hooks/schemas/context.ts", "src/hooks/schemas/db/context.ts", "src/hooks/schemas/db/payload.ts", "src/hooks/schemas/satellite.env.ts", "src/hooks/db/hooks.ts", "src/polyfills/console.polyfill.ts"],
|
|
4
|
-
"sourcesContent": ["import * as z from 'zod';\nimport {CollectionsSchema} from '../schemas/collections';\nimport {AssertFunctionSchema} from '../schemas/context';\nimport {AssertSetDocContextSchema} from '../schemas/db/context';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\n\n/**\n * A generic schema for defining assertions related to collections.\n *\n * @template T - The type of context passed to the assertions when triggered.\n */\nconst OnAssertSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n /**\n * A function that runs when the assertion is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {void} Resolves when the assertion completes.\n */\n assert: AssertFunctionSchema<T>(contextSchema)\n }).strict();\n\n/**\n * @see AssertSetDoc\n */\nexport const AssertSetDocSchema = OnAssertSchema(AssertSetDocContextSchema);\n\n/**\n * An assertion that runs when a document is created or updated.\n */\nexport type AssertSetDoc = z.infer<typeof AssertSetDocSchema>;\n\n// TODO: to be extended\n/**\n * @see Assert\n */\nexport const AssertSchema = AssertSetDocSchema;\n\n/**\n * All assertions definitions.\n */\nexport type Assert = z.infer<typeof AssertSchema>;\n\nexport const AssertFnSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.function().args(SatelliteEnvSchema).returns(assertSchema);\nexport type AssertFn<T extends Assert> = (assert: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const AssertFnOrObjectSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.union([assertSchema, AssertFnSchema(assertSchema)]);\nexport type AssertFnOrObject<T extends Assert> = T | AssertFn<T>;\n\nexport function defineAssert<T extends Assert>(assert: T): T;\nexport function defineAssert<T extends Assert>(assert: AssertFn<T>): AssertFn<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T> {\n return assert;\n}\n", "import * as z from 'zod';\n\n/**\n * @see Collections\n */\nexport const CollectionsSchema = z\n .object({\n /**\n * An array containing at least one collection name where the hook or assertion will be executed.\n */\n collections: z.array(z.string()).min(1).readonly()\n })\n .strict();\n\n/**\n * Defines the collections where a hook or assertion should run.\n */\nexport type Collections = z.infer<typeof CollectionsSchema>;\n", "import * as z from 'zod';\nimport {RawUserIdSchema} from '../../schemas/satellite';\n\n/**\n * @see HookContext\n */\nexport const HookContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) =>\n z\n .object({\n /**\n * The user who originally triggered the function that in turn triggered the hook.\n */\n caller: RawUserIdSchema,\n\n /**\n * The data associated with the hook execution.\n */\n data: dataSchema\n })\n .strict();\n\n/**\n * Represents the context provided to hooks, containing information about the caller and related data.\n *\n * @template T - The type of data associated with the hook.\n */\nexport type HookContext<T extends z.ZodTypeAny> = z.infer<ReturnType<typeof HookContextSchema<T>>>;\n\n/**\n * @see AssertFunction\n */\nexport const AssertFunctionSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n z.function().args(contextSchema).returns(z.void());\n\n/**\n * Defines the `assert` function schema for assertions.\n *\n * The function takes a context argument and returns `void`.\n *\n * @template T - The type of context passed to the function.\n */\nexport type AssertFunction<T> = z.infer<ReturnType<typeof AssertFunctionSchema<z.ZodType<T>>>>;\n\n/**\n * @see RunFunction\n */\nexport const RunFunctionSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n z.function().args(contextSchema).returns(z.promise(z.void()).or(z.void()));\n\n/**\n * Defines the `run` function schema for hooks.\n *\n * The function takes a context argument and returns either a `Promise<void>` or `void`.\n *\n * @template T - The type of context passed to the function.\n */\nexport type RunFunction<T> = z.infer<ReturnType<typeof RunFunctionSchema<z.ZodType<T>>>>;\n", "import * as z from 'zod';\nimport {CollectionSchema, KeySchema} from '../../../schemas/satellite';\nimport {HookContextSchema} from '../context';\nimport {DocAssertSetSchema, DocUpsertSchema} from './payload';\n\n/**\n * @see DocContext\n */\nexport const DocContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) =>\n z\n .object({\n /**\n * The name of the collection where the document is stored.\n */\n collection: CollectionSchema,\n\n /**\n * The unique key identifying the document within the collection.\n */\n key: KeySchema,\n\n /**\n * The data associated with the document operation.\n */\n data: dataSchema\n })\n .strict();\n\n/**\n * Represents the context of a document operation within a collection.\n *\n * @template T - The type of data associated with the document.\n */\nexport type DocContext<T extends z.ZodTypeAny> = z.infer<ReturnType<typeof DocContextSchema<T>>>;\n\n/**\n * @see OnSetDocContext\n */\nexport const OnSetDocContextSchema = HookContextSchema(DocContextSchema(DocUpsertSchema));\n\n/**\n * The context provided to the `onSetDoc` hook.\n *\n * This context contains information about the document being created or updated,\n * along with details about the user who triggered the operation.\n */\nexport type OnSetDocContext = z.infer<typeof OnSetDocContextSchema>;\n\n/**\n * @see AssertSetDocContext\n */\nexport const AssertSetDocContextSchema = HookContextSchema(DocContextSchema(DocAssertSetSchema));\n\n/**\n * The context provided to the `assertSetDoc` hook.\n *\n * This context contains information about the document being validated before\n * it is created or updated. If validation fails, the developer should throw an error.\n */\nexport type AssertSetDocContext = z.infer<typeof AssertSetDocContextSchema>;\n", "import * as z from 'zod';\nimport {DocDescriptionSchema, DocSchema, RawDataSchema} from '../../../schemas/db';\nimport {VersionSchema} from '../../../schemas/satellite';\n\n/**\n * @see DocUpsert\n */\nexport const DocUpsertSchema = z\n .object({\n /**\n * The previous version of the document before the update.\n * Undefined if this is a new document.\n */\n before: DocSchema.optional(),\n\n /**\n * The new version of the document after the update.\n */\n after: DocSchema\n })\n .strict();\n\n/**\n * Represents a document update operation.\n *\n * This is used in hooks where a document is either being created or updated.\n */\nexport type DocUpsert = z.infer<typeof DocUpsertSchema>;\n\n/**\n * @see ProposedDoc\n */\nexport const ProposedDocSchema = z\n .object({\n /**\n * The raw data of the document.\n */\n data: RawDataSchema,\n\n /**\n * An optional description of the document.\n */\n description: DocDescriptionSchema.optional(),\n\n /**\n * The expected version number to ensure consistency.\n */\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents the proposed version of a document.\n * This can be validated before allowing the operation.\n */\nexport type ProposedDoc = z.infer<typeof ProposedDocSchema>;\n\n/**\n * @see DocAssertSet\n */\nexport const DocAssertSetSchema = z\n .object({\n /**\n * The current version of the document before the operation.\n * Undefined if this is a new document.\n */\n current: DocSchema.optional(),\n\n /**\n * The proposed version of the document.\n * This can be validated before allowing the operation.\n */\n proposed: ProposedDocSchema\n })\n .strict();\n\n/**\n * Represents a validation check before setting a document.\n *\n * The developer can compare the `current` and `proposed` versions and\n * throw an error if their validation fails.\n */\nexport type DocAssertSet = z.infer<typeof DocAssertSetSchema>;\n", "import * as z from 'zod';\n\n/**\n * @see SatelliteEnv\n */\nexport const SatelliteEnvSchema = z.record(z.unknown());\n\n/**\n * Placeholder for future environment-specific configurations.\n *\n * Currently unused, but it may support features such as:\n * - Defining the execution mode (e.g., staging or production).\n * - Providing environment-specific values like `ckBtcLedgerId` for test or production.\n */\nexport type SatelliteEnv = z.infer<typeof SatelliteEnvSchema>;\n", "import * as z from 'zod';\nimport {CollectionsSchema} from '../schemas/collections';\nimport {RunFunctionSchema} from '../schemas/context';\nimport {OnSetDocContextSchema} from '../schemas/db/context';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\n\n/**\n * A generic schema for defining hooks related to collections.\n *\n * @template T - The type of context passed to the hook when triggered.\n */\nconst OnHookSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n /**\n * A function that runs when the hook is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {Promise<void>} Resolves when the operation completes.\n */\n run: RunFunctionSchema<T>(contextSchema)\n }).strict();\n\n/**\n * @see OnSetDoc\n */\nexport const OnSetDocSchema = OnHookSchema(OnSetDocContextSchema);\n\n/**\n * A hook that runs when a document is created or updated.\n */\nexport type OnSetDoc = z.infer<typeof OnSetDocSchema>;\n\n// TODO: to be extended\n/**\n * @see Hook\n */\nexport const HookSchema = OnSetDocSchema;\n\n/**\n * All hooks definitions.\n */\nexport type Hook = z.infer<typeof HookSchema>;\n\nexport const HookFnSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.function().args(SatelliteEnvSchema).returns(hookSchema);\nexport type HookFn<T extends Hook> = (hook: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const HookFnOrObjectSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.union([hookSchema, HookFnSchema(hookSchema)]);\nexport type HookFnOrObject<T extends Hook> = T | HookFn<T>;\n\nexport function defineHook<T extends Hook>(hook: T): T;\nexport function defineHook<T extends Hook>(hook: HookFn<T>): HookFn<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T> {\n return hook;\n}\n", "import {jsonReplacer} from '@dfinity/utils';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst __juno_satellite_console_log = (v: any[]) => {\n const msg = v\n .map((arg) => (typeof arg === 'object' ? JSON.stringify(arg, jsonReplacer) : arg))\n .join(' ');\n\n globalThis.__ic_cdk_print(msg);\n};\n\n// @ts-expect-error We want to override the console\nglobalThis.console = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n info(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n log(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n warn(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error(...v: any[]) {\n __juno_satellite_console_log(v);\n }\n};\n"],
|
|
5
|
-
"mappings": "sJAAA,UAAYA,MAAO,MCAnB,UAAYC,MAAO,MAKZ,IAAMC,EACV,SAAO,
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod';\nimport {CollectionsSchema} from '../schemas/collections';\nimport {AssertFunctionSchema} from '../schemas/context';\nimport {AssertSetDocContextSchema} from '../schemas/db/context';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\n\n/**\n * A generic schema for defining assertions related to collections.\n *\n * @template T - The type of context passed to the assertions when triggered.\n */\nconst OnAssertSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n /**\n * A function that runs when the assertion is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {void} Resolves when the assertion completes.\n */\n assert: AssertFunctionSchema<T>(contextSchema)\n }).strict();\n\n/**\n * @see AssertSetDoc\n */\nexport const AssertSetDocSchema = OnAssertSchema(AssertSetDocContextSchema);\n\n/**\n * An assertion that runs when a document is created or updated.\n */\nexport type AssertSetDoc = z.infer<typeof AssertSetDocSchema>;\n\n// TODO: to be extended\n/**\n * @see Assert\n */\nexport const AssertSchema = AssertSetDocSchema;\n\n/**\n * All assertions definitions.\n */\nexport type Assert = z.infer<typeof AssertSchema>;\n\nexport const AssertFnSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.function().args(SatelliteEnvSchema).returns(assertSchema);\nexport type AssertFn<T extends Assert> = (assert: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const AssertFnOrObjectSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.union([assertSchema, AssertFnSchema(assertSchema)]);\nexport type AssertFnOrObject<T extends Assert> = T | AssertFn<T>;\n\nexport function defineAssert<T extends Assert>(assert: T): T;\nexport function defineAssert<T extends Assert>(assert: AssertFn<T>): AssertFn<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T> {\n return assert;\n}\n", "import * as z from 'zod';\n\n/**\n * @see Collections\n */\nexport const CollectionsSchema = z\n .object({\n /**\n * An array of collection names where the hook or assertion will run.\n * If empty, no hooks or assertions are triggered.\n */\n collections: z.array(z.string()).readonly()\n })\n .strict();\n\n/**\n * Defines the collections where a hook or assertion should run.\n */\nexport type Collections = z.infer<typeof CollectionsSchema>;\n", "import * as z from 'zod';\nimport {RawUserIdSchema} from '../../schemas/satellite';\n\n/**\n * @see HookContext\n */\nexport const HookContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) =>\n z\n .object({\n /**\n * The user who originally triggered the function that in turn triggered the hook.\n */\n caller: RawUserIdSchema,\n\n /**\n * The data associated with the hook execution.\n */\n data: dataSchema\n })\n .strict();\n\n/**\n * Represents the context provided to hooks, containing information about the caller and related data.\n *\n * @template T - The type of data associated with the hook.\n */\nexport type HookContext<T extends z.ZodTypeAny> = z.infer<ReturnType<typeof HookContextSchema<T>>>;\n\n/**\n * @see AssertFunction\n */\nexport const AssertFunctionSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n z.function().args(contextSchema).returns(z.void());\n\n/**\n * Defines the `assert` function schema for assertions.\n *\n * The function takes a context argument and returns `void`.\n *\n * @template T - The type of context passed to the function.\n */\nexport type AssertFunction<T> = z.infer<ReturnType<typeof AssertFunctionSchema<z.ZodType<T>>>>;\n\n/**\n * @see RunFunction\n */\nexport const RunFunctionSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n z.function().args(contextSchema).returns(z.promise(z.void()).or(z.void()));\n\n/**\n * Defines the `run` function schema for hooks.\n *\n * The function takes a context argument and returns either a `Promise<void>` or `void`.\n *\n * @template T - The type of context passed to the function.\n */\nexport type RunFunction<T> = z.infer<ReturnType<typeof RunFunctionSchema<z.ZodType<T>>>>;\n", "import * as z from 'zod';\nimport {CollectionSchema, KeySchema} from '../../../schemas/satellite';\nimport {HookContextSchema} from '../context';\nimport {DocAssertSetSchema, DocUpsertSchema} from './payload';\n\n/**\n * @see DocContext\n */\nexport const DocContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) =>\n z\n .object({\n /**\n * The name of the collection where the document is stored.\n */\n collection: CollectionSchema,\n\n /**\n * The unique key identifying the document within the collection.\n */\n key: KeySchema,\n\n /**\n * The data associated with the document operation.\n */\n data: dataSchema\n })\n .strict();\n\n/**\n * Represents the context of a document operation within a collection.\n *\n * @template T - The type of data associated with the document.\n */\nexport type DocContext<T extends z.ZodTypeAny> = z.infer<ReturnType<typeof DocContextSchema<T>>>;\n\n/**\n * @see OnSetDocContext\n */\nexport const OnSetDocContextSchema = HookContextSchema(DocContextSchema(DocUpsertSchema));\n\n/**\n * The context provided to the `onSetDoc` hook.\n *\n * This context contains information about the document being created or updated,\n * along with details about the user who triggered the operation.\n */\nexport type OnSetDocContext = z.infer<typeof OnSetDocContextSchema>;\n\n/**\n * @see AssertSetDocContext\n */\nexport const AssertSetDocContextSchema = HookContextSchema(DocContextSchema(DocAssertSetSchema));\n\n/**\n * The context provided to the `assertSetDoc` hook.\n *\n * This context contains information about the document being validated before\n * it is created or updated. If validation fails, the developer should throw an error.\n */\nexport type AssertSetDocContext = z.infer<typeof AssertSetDocContextSchema>;\n", "import * as z from 'zod';\nimport {DocDescriptionSchema, DocSchema, RawDataSchema} from '../../../schemas/db';\nimport {VersionSchema} from '../../../schemas/satellite';\n\n/**\n * @see DocUpsert\n */\nexport const DocUpsertSchema = z\n .object({\n /**\n * The previous version of the document before the update.\n * Undefined if this is a new document.\n */\n before: DocSchema.optional(),\n\n /**\n * The new version of the document after the update.\n */\n after: DocSchema\n })\n .strict();\n\n/**\n * Represents a document update operation.\n *\n * This is used in hooks where a document is either being created or updated.\n */\nexport type DocUpsert = z.infer<typeof DocUpsertSchema>;\n\n/**\n * @see ProposedDoc\n */\nexport const ProposedDocSchema = z\n .object({\n /**\n * The raw data of the document.\n */\n data: RawDataSchema,\n\n /**\n * An optional description of the document.\n */\n description: DocDescriptionSchema.optional(),\n\n /**\n * The expected version number to ensure consistency.\n */\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents the proposed version of a document.\n * This can be validated before allowing the operation.\n */\nexport type ProposedDoc = z.infer<typeof ProposedDocSchema>;\n\n/**\n * @see DocAssertSet\n */\nexport const DocAssertSetSchema = z\n .object({\n /**\n * The current version of the document before the operation.\n * Undefined if this is a new document.\n */\n current: DocSchema.optional(),\n\n /**\n * The proposed version of the document.\n * This can be validated before allowing the operation.\n */\n proposed: ProposedDocSchema\n })\n .strict();\n\n/**\n * Represents a validation check before setting a document.\n *\n * The developer can compare the `current` and `proposed` versions and\n * throw an error if their validation fails.\n */\nexport type DocAssertSet = z.infer<typeof DocAssertSetSchema>;\n", "import * as z from 'zod';\n\n/**\n * @see SatelliteEnv\n */\nexport const SatelliteEnvSchema = z.record(z.unknown());\n\n/**\n * Placeholder for future environment-specific configurations.\n *\n * Currently unused, but it may support features such as:\n * - Defining the execution mode (e.g., staging or production).\n * - Providing environment-specific values like `ckBtcLedgerId` for test or production.\n */\nexport type SatelliteEnv = z.infer<typeof SatelliteEnvSchema>;\n", "import * as z from 'zod';\nimport {CollectionsSchema} from '../schemas/collections';\nimport {RunFunctionSchema} from '../schemas/context';\nimport {OnSetDocContextSchema} from '../schemas/db/context';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\n\n/**\n * A generic schema for defining hooks related to collections.\n *\n * @template T - The type of context passed to the hook when triggered.\n */\nconst OnHookSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n /**\n * A function that runs when the hook is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {Promise<void>} Resolves when the operation completes.\n */\n run: RunFunctionSchema<T>(contextSchema)\n }).strict();\n\n/**\n * @see OnSetDoc\n */\nexport const OnSetDocSchema = OnHookSchema(OnSetDocContextSchema);\n\n/**\n * A hook that runs when a document is created or updated.\n */\nexport type OnSetDoc = z.infer<typeof OnSetDocSchema>;\n\n// TODO: to be extended\n/**\n * @see Hook\n */\nexport const HookSchema = OnSetDocSchema;\n\n/**\n * All hooks definitions.\n */\nexport type Hook = z.infer<typeof HookSchema>;\n\nexport const HookFnSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.function().args(SatelliteEnvSchema).returns(hookSchema);\nexport type HookFn<T extends Hook> = (hook: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const HookFnOrObjectSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.union([hookSchema, HookFnSchema(hookSchema)]);\nexport type HookFnOrObject<T extends Hook> = T | HookFn<T>;\n\nexport function defineHook<T extends Hook>(hook: T): T;\nexport function defineHook<T extends Hook>(hook: HookFn<T>): HookFn<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T> {\n return hook;\n}\n", "import {jsonReplacer} from '@dfinity/utils';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst __juno_satellite_console_log = (v: any[]) => {\n const msg = v\n .map((arg) => (typeof arg === 'object' ? JSON.stringify(arg, jsonReplacer) : arg))\n .join(' ');\n\n globalThis.__ic_cdk_print(msg);\n};\n\n// @ts-expect-error We want to override the console\nglobalThis.console = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n info(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n log(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n warn(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error(...v: any[]) {\n __juno_satellite_console_log(v);\n }\n};\n"],
|
|
5
|
+
"mappings": "sJAAA,UAAYA,MAAO,MCAnB,UAAYC,MAAO,MAKZ,IAAMC,EACV,SAAO,CAKN,YAAe,QAAQ,SAAO,CAAC,EAAE,SAAS,CAC5C,CAAC,EACA,OAAO,ECbV,UAAYC,MAAO,MAMZ,IAAMC,EAA6CC,GAErD,SAAO,CAIN,OAAQC,EAKR,KAAMD,CACR,CAAC,EACA,OAAO,EAYCE,EAAgDC,GACzD,WAAS,EAAE,KAAKA,CAAa,EAAE,QAAU,OAAK,CAAC,EActCC,EAA6CD,GACtD,WAAS,EAAE,KAAKA,CAAa,EAAE,QAAU,UAAU,OAAK,CAAC,EAAE,GAAK,OAAK,CAAC,CAAC,EC/C3E,UAAYE,MAAO,MCAnB,UAAYC,MAAO,MAOZ,IAAMC,EACV,SAAO,CAKN,OAAQC,EAAU,SAAS,EAK3B,MAAOA,CACT,CAAC,EACA,OAAO,EAYGC,EACV,SAAO,CAIN,KAAMC,EAKN,YAAaC,EAAqB,SAAS,EAK3C,QAASC,EAAc,SAAS,CAClC,CAAC,EACA,OAAO,EAWGC,EACV,SAAO,CAKN,QAASL,EAAU,SAAS,EAM5B,SAAUC,CACZ,CAAC,EACA,OAAO,EDlEH,IAAMK,EAA4CC,GAEpD,SAAO,CAIN,WAAYC,EAKZ,IAAKC,EAKL,KAAMF,CACR,CAAC,EACA,OAAO,EAYCG,EAAwBC,EAAkBL,EAAiBM,CAAe,CAAC,EAa3EC,EAA4BF,EAAkBL,EAAiBQ,CAAkB,CAAC,EEnD/F,UAAYC,MAAO,MAKZ,IAAMC,EAAuB,SAAS,UAAQ,CAAC,ELMtD,IAAMC,EAA0CC,GAC9CC,EAAkB,OAAO,CAOvB,OAAQC,EAAwBF,CAAa,CAC/C,CAAC,EAAE,OAAO,EAKCG,EAAqBJ,EAAeK,CAAyB,EAW7DC,GAAeF,EAOfG,EAA0CC,GACnD,WAAS,EAAE,KAAKC,CAAkB,EAAE,QAAQD,CAAY,EAG/CE,GAAkDF,GAC3D,QAAM,CAACA,EAAcD,EAAeC,CAAY,CAAC,CAAC,EAM/C,SAASG,GAA+BC,EAAkD,CAC/F,OAAOA,CACT,CMxDA,UAAYC,MAAO,MAWnB,IAAMC,EAAwCC,GAC5CC,EAAkB,OAAO,CAOvB,IAAKC,EAAqBF,CAAa,CACzC,CAAC,EAAE,OAAO,EAKCG,EAAiBJ,EAAaK,CAAqB,EAWnDC,GAAaF,EAObG,EAAwCC,GACjD,WAAS,EAAE,KAAKC,CAAkB,EAAE,QAAQD,CAAU,EAG7CE,GAAgDF,GACzD,QAAM,CAACA,EAAYD,EAAaC,CAAU,CAAC,CAAC,EAMzC,SAASG,GAA2BC,EAA4C,CACrF,OAAOA,CACT,CCxDA,OAAQ,gBAAAC,MAAmB,iBAG3B,IAAMC,EAAgCC,GAAa,CACjD,IAAMC,EAAMD,EACT,IAAKE,GAAS,OAAOA,GAAQ,SAAW,KAAK,UAAUA,EAAKJ,CAAY,EAAII,CAAI,EAChF,KAAK,GAAG,EAEX,WAAW,eAAeD,CAAG,CAC/B,EAGA,WAAW,QAAU,CAEnB,QAAQD,EAAU,CAChBD,EAA6BC,CAAC,CAChC,EAEA,OAAOA,EAAU,CACfD,EAA6BC,CAAC,CAChC,EAEA,QAAQA,EAAU,CAChBD,EAA6BC,CAAC,CAChC,EAEA,SAASA,EAAU,CACjBD,EAA6BC,CAAC,CAChC,CACF",
|
|
6
6
|
"names": ["z", "z", "CollectionsSchema", "z", "HookContextSchema", "dataSchema", "RawUserIdSchema", "AssertFunctionSchema", "contextSchema", "RunFunctionSchema", "z", "z", "DocUpsertSchema", "DocSchema", "ProposedDocSchema", "RawDataSchema", "DocDescriptionSchema", "VersionSchema", "DocAssertSetSchema", "DocContextSchema", "dataSchema", "CollectionSchema", "KeySchema", "OnSetDocContextSchema", "HookContextSchema", "DocUpsertSchema", "AssertSetDocContextSchema", "DocAssertSetSchema", "z", "SatelliteEnvSchema", "OnAssertSchema", "contextSchema", "CollectionsSchema", "AssertFunctionSchema", "AssertSetDocSchema", "AssertSetDocContextSchema", "AssertSchema", "AssertFnSchema", "assertSchema", "SatelliteEnvSchema", "AssertFnOrObjectSchema", "defineAssert", "assert", "z", "OnHookSchema", "contextSchema", "CollectionsSchema", "RunFunctionSchema", "OnSetDocSchema", "OnSetDocContextSchema", "HookSchema", "HookFnSchema", "hookSchema", "SatelliteEnvSchema", "HookFnOrObjectSchema", "defineHook", "hook", "jsonReplacer", "__juno_satellite_console_log", "v", "msg", "arg"]
|
|
7
7
|
}
|
package/package.json
CHANGED