@junobuild/functions 0.3.2 → 0.3.3

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.
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["src/schemas/satellite.ts", "src/schemas/db.ts", "src/schemas/storage.ts", "src/schemas/list.ts"],
4
- "sourcesContent": ["import * as z from 'zod/v4';\nimport {PrincipalSchema, RawPrincipalSchema} from './candid';\n\n/**\n * @see Timestamp\n */\nexport const TimestampSchema = z.bigint();\n\n/**\n * Represents a timestamp in nanoseconds since the Unix epoch.\n *\n * Used for tracking when events occur, such as document creation and updates.\n */\nexport type Timestamp = z.infer<typeof TimestampSchema>;\n\n/**\n * @see Version\n */\nexport const VersionSchema = z.bigint();\n\n/**\n * Represents a version number for tracking changes.\n *\n * This is typically incremented with each update to ensure consistency.\n */\nexport type Version = z.infer<typeof VersionSchema>;\n\n/**\n * @see RawUserId\n */\nexport const RawUserIdSchema = RawPrincipalSchema;\n\n/**\n * Represents a raw user identifier.\n *\n * This is a principal associated with a user.\n */\nexport type RawUserId = z.infer<typeof RawUserIdSchema>;\n\n/**\n * @see UserId\n */\nexport const UserIdSchema = PrincipalSchema;\n\n/**\n * Represents a user identifier.\n *\n * This is a principal associated with a user.\n */\nexport type UserId = z.infer<typeof UserIdSchema>;\n\n/**\n * @see Collection\n */\nexport const CollectionSchema = z.string();\n\n/**\n * A collection name where data are stored.\n */\nexport type Collection = z.infer<typeof CollectionSchema>;\n\n/**\n * @see Key\n */\nexport const KeySchema = z.string();\n\n/**\n * A key identifier within a collection.\n */\nexport type Key = z.infer<typeof KeySchema>;\n\n/**\n * @see Description\n */\nexport const DescriptionSchema = z.string().max(1024);\n\n/**\n * Represents a description with a maximum length of 1024 characters.\n * Used for document and asset fields which can be useful for search purpose.\n */\nexport type Description = z.infer<typeof DescriptionSchema>;\n", "import * as z from 'zod/v4';\nimport {Uint8ArraySchema} from './candid';\nimport {\n type Description,\n DescriptionSchema,\n type RawUserId,\n RawUserIdSchema,\n type Timestamp,\n TimestampSchema,\n type Version,\n VersionSchema\n} from './satellite';\n\n/**\n * @see RawData\n */\nexport const RawDataSchema = Uint8ArraySchema;\n\n/**\n * Represents raw binary data.\n *\n * This is used to store structured data in a document.\n */\nexport type RawData = z.infer<typeof Uint8ArraySchema>;\n\n/**\n * @see Doc\n */\nexport const DocSchema = z\n .object({\n owner: RawUserIdSchema,\n data: RawDataSchema,\n description: DescriptionSchema.optional(),\n created_at: TimestampSchema,\n updated_at: TimestampSchema,\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents a document stored in a collection.\n */\nexport interface Doc {\n /**\n * The user who owns this document.\n */\n owner: RawUserId;\n\n /**\n * The raw data of the document.\n */\n data: RawData;\n\n /**\n * An optional description of the document.\n */\n description?: Description;\n\n /**\n * The timestamp when the document was first created.\n */\n created_at: Timestamp;\n\n /**\n * The timestamp when the document was last updated.\n */\n updated_at: Timestamp;\n\n /**\n * The version number of the document, used for consistency checks.\n * If not provided, it's assumed to be the first version.\n */\n version?: Version;\n}\n\n/**\n * @see OptionDoc\n */\nexport const OptionDocSchema = DocSchema.optional();\n\n/**\n * A shorthand for a document that might or not be defined.\n */\nexport type OptionDoc = Doc | undefined;\n\n/**\n * @see SetDoc\n */\nexport const SetDocSchema = z\n .object({\n data: RawDataSchema,\n description: DescriptionSchema.optional(),\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents the proposed version of a document to be created or updated.\n * This can be validated before allowing the operation.\n */\nexport interface SetDoc {\n /**\n * The raw data of the document.\n */\n data: RawData;\n\n /**\n * An optional description of the document.\n */\n description?: Description;\n\n /**\n * The expected version number to ensure consistency.\n */\n version?: Version;\n}\n\n/**\n * @see DelDoc\n */\nexport const DelDocSchema = z\n .object({\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents the proposed version of a document to be deleted.\n * This can be validated before allowing the operation.\n */\nexport interface DelDoc {\n /**\n * The expected version number to ensure consistency.\n */\n version?: Version;\n}\n", "import * as z from 'zod/v4';\nimport {Uint8ArraySchema} from './candid';\nimport {\n type Collection,\n CollectionSchema,\n type Description,\n DescriptionSchema,\n type RawUserId,\n RawUserIdSchema,\n type Timestamp,\n TimestampSchema,\n type Version,\n VersionSchema\n} from './satellite';\n\n/**\n * @see HeaderField\n */\nconst HeaderFieldSchema = z.tuple([z.string(), z.string()]);\n\n/**\n * Represents a single HTTP header as a tuple of name and value.\n */\nexport type HeaderField = [string, string];\n\n/**\n * @see HeaderFields\n */\nexport const HeaderFieldsSchema = z.array(HeaderFieldSchema);\n\n/**\n * Represents a list of HTTP headers.\n */\nexport type HeaderFields = HeaderField[];\n\n/**\n * @see Blob\n */\nexport const BlobSchema = Uint8ArraySchema;\n\n/**\n * Binary content used in asset encoding.\n */\nexport type Blob = Uint8Array;\n\n/**\n * @see BlobOrKey\n */\nconst BlobOrKeySchema = BlobSchema;\n\n/**\n * When stable memory is used, chunks are saved within a StableBTreeMap and their keys - StableEncodingChunkKey - are saved for reference as serialized values\n */\nexport type BlobOrKey = Uint8Array;\n\n/**\n * @see Hash\n */\nconst HashSchema = z.instanceof(Uint8Array).refine((val) => val.length === 32, {\n message: 'Hash must be a Uint8Array of length 32'\n});\n\n/**\n * Represents a SHA-256 hash as a 32-byte binary value.\n */\nexport type Hash = Uint8Array;\n\n/**\n * @see AssetKey\n */\nexport const AssetKeySchema = z\n .object({\n name: z.string(),\n full_path: z.string(),\n token: z.string().optional(),\n collection: CollectionSchema,\n owner: RawUserIdSchema,\n description: DescriptionSchema.optional()\n })\n .strict();\n\n/**\n * Metadata identifying an asset within a collection and the storage system.\n */\nexport interface AssetKey {\n /**\n * The name of the asset (e.g., \"logo.png\").\n */\n name: string;\n\n /**\n * The full relative path of the asset (e.g., \"/images/logo.png\").\n */\n full_path: string;\n\n /**\n * Optional access token for the asset.\n * If set, can be used using a query parameter e.g. /full_path/?token=1223-3345-5564-3333\n */\n token?: string;\n\n /**\n * The collection to which this asset belongs.\n */\n collection: Collection;\n\n /**\n * The owner of the asset.\n */\n owner: RawUserId;\n\n /**\n * Optional description of the asset for indexing/search.\n */\n description?: Description;\n}\n\n/**\n * @see AssetEncoding\n */\nexport const AssetEncodingSchema = z.object({\n modified: TimestampSchema,\n content_chunks: z.array(BlobOrKeySchema),\n total_length: z.bigint(),\n sha256: HashSchema\n});\n\n/**\n * Represents a specific encoding of an asset, such as \"gzip\" or \"identity\" (no compression).\n */\nexport interface AssetEncoding {\n /**\n * Timestamp when the encoding was last modified.\n */\n modified: Timestamp;\n\n /**\n * Chunks of binary content or references to them.\n */\n content_chunks: BlobOrKey[];\n\n /**\n * Total byte size of the encoded content.\n */\n total_length: bigint;\n\n /**\n * SHA-256 hash of the encoded content.\n */\n sha256: Hash;\n}\n\n/**\n * @see AssetEncodingNoContent\n */\nconst AssetEncodingNoContentSchema = AssetEncodingSchema.omit({content_chunks: true}).strict();\n\n/**\n * Represents a specific encoding of an asset, such as \"gzip\" or \"identity\" (no compression), without the chunks.\n */\nexport type AssetEncodingNoContent = Omit<AssetEncoding, 'content_chunks'>;\n\n/**\n * @see EncodingType\n */\nconst EncodingTypeSchema = z.enum(['identity', 'gzip', 'compress', 'deflate', 'br']);\n\n/**\n * A string identifier representing a specific encoding format (e.g., \"gzip\", \"identity\").\n */\nexport type EncodingType = 'identity' | 'gzip' | 'compress' | 'deflate' | 'br';\n\n/**\n * @see Asset\n */\nexport const AssetSchema = z\n .object({\n key: AssetKeySchema,\n headers: HeaderFieldsSchema,\n encodings: z.array(z.tuple([EncodingTypeSchema, AssetEncodingSchema])),\n created_at: TimestampSchema,\n updated_at: TimestampSchema,\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * A stored asset including its metadata, encodings, and timestamps.\n */\nexport interface Asset {\n /**\n * Metadata about the asset's identity and ownership.\n */\n key: AssetKey;\n\n /**\n * Optional HTTP headers associated with the asset.\n */\n headers: HeaderField[];\n\n /**\n * A mapping from encoding types (e.g., \"identity\", \"gzip\") to the corresponding encoded version.\n */\n encodings: [EncodingType, AssetEncoding][];\n\n /**\n * Timestamp when the asset was created.\n */\n created_at: Timestamp;\n\n /**\n * Timestamp when the asset was last updated.\n */\n updated_at: Timestamp;\n\n /**\n * Optional version number of the asset.\n */\n version?: Version;\n}\n\n/**\n * @see AssetNoContent\n */\nexport const AssetNoContentSchema = AssetSchema.omit({encodings: true})\n .extend({\n encodings: z.array(z.tuple([EncodingTypeSchema, AssetEncodingNoContentSchema]))\n })\n .strict();\n\n/**\n * A stored asset including its metadata, encodings without chunks, and timestamps.\n */\nexport type AssetNoContent = Omit<Asset, 'encodings'> & {\n encodings: [EncodingType, AssetEncodingNoContent][];\n};\n\n/**\n * @see ReferenceId\n */\nconst ReferenceIdSchema = z.bigint();\n\n/**\n * A unique reference identifier for batches.\n */\nexport type ReferenceId = bigint;\n\n/**\n * @see Batch\n */\nexport const BatchSchema = z\n .object({\n key: AssetKeySchema,\n reference_id: ReferenceIdSchema.optional(),\n expires_at: TimestampSchema,\n encoding_type: EncodingTypeSchema.optional()\n })\n .strict();\n\n/**\n * Represents a batch of chunks to be uploaded and committed to an asset.\n */\nexport interface Batch {\n /**\n * The metadata key for the asset being uploaded.\n */\n key: AssetKey;\n\n /**\n * Optional reference ID for tracking or validation.\n */\n reference_id?: ReferenceId;\n\n /**\n * Timestamp when this batch expires.\n */\n expires_at: Timestamp;\n\n /**\n * Optional encoding format (e.g., \"gzip\").\n */\n encoding_type?: EncodingType;\n}\n\n/**\n * @see ChunkId\n */\nconst ChunkIdSchema = z.bigint();\n\n/**\n * A unique identifier representing a single chunk of data.\n */\nexport type ChunkId = bigint;\n\n/**\n * @see BatchId\n */\nconst BatchIdSchema = z.bigint();\n\n/**\n * A unique identifier representing a batch of upload.\n */\nexport type BatchId = bigint;\n\n/**\n * @see CommitBatch\n */\nexport const CommitBatchSchema = z\n .object({\n batch_id: BatchIdSchema,\n headers: HeaderFieldsSchema,\n chunk_ids: z.array(ChunkIdSchema)\n })\n .strict();\n\n/**\n * Represents the final step in uploading an asset, committing the batch to storage.\n */\nexport interface CommitBatch {\n /**\n * The ID of the batch being committed.\n */\n batch_id: BatchId;\n\n /**\n * HTTP headers associated with this asset.\n */\n headers: HeaderField[];\n\n /**\n * List of chunk IDs that make up the asset content.\n */\n chunk_ids: ChunkId[];\n}\n\n/**\n * @see FullPath\n */\nexport const FullPathSchema = z.string();\n\n/**\n * Represents the relative path of an asset in storage.\n * For assets that are not part of the frontend app, the collection must be included at the root of the path.\n *\n * Example: `/images/a-sun-above-the-mountains.png`\n */\nexport type FullPath = string;\n\n/**\n * @see OptionAsset\n */\nexport const OptionAssetSchema = AssetSchema.optional();\n\n/**\n * A shorthand for an asset that might or not be defined.\n */\nexport type OptionAsset = Asset | undefined;\n", "import * as z from 'zod/v4';\nimport {\n type Description,\n type Key,\n type RawUserId,\n type Timestamp,\n DescriptionSchema,\n KeySchema,\n RawUserIdSchema,\n TimestampSchema\n} from './satellite';\n\n/**\n * @see TimestampMatcher\n */\nexport const TimestampMatcherSchema = z.union([\n z.object({equal: TimestampSchema}),\n z.object({greater_than: TimestampSchema}),\n z.object({less_than: TimestampSchema}),\n z.object({between: z.tuple([TimestampSchema, TimestampSchema])})\n]);\n\n/**\n * TimestampMatcher matches a timestamp field using a specific strategy.\n */\nexport type TimestampMatcher =\n | {equal: Timestamp}\n | {greater_than: Timestamp}\n | {less_than: Timestamp}\n | {between: [Timestamp, Timestamp]};\n\n/**\n * @see ListMatcher\n */\nexport const ListMatcherSchema = z\n .object({\n key: KeySchema.optional(),\n description: DescriptionSchema.optional(),\n created_at: TimestampMatcherSchema.optional(),\n updated_at: TimestampMatcherSchema.optional()\n })\n .strict();\n\n/**\n * Matcher used to filter list results.\n */\nexport interface ListMatcher {\n key?: Key;\n description?: Description;\n created_at?: TimestampMatcher;\n updated_at?: TimestampMatcher;\n}\n\n/**\n * @see ListPaginate\n */\nexport const ListPaginateSchema = z\n .object({\n start_after: KeySchema.optional(),\n limit: z.bigint().optional()\n })\n .strict();\n\n/**\n * Optional pagination controls for listing.\n */\nexport interface ListPaginate {\n start_after?: Key;\n limit?: bigint;\n}\n\n/**\n * @see ListOrderField\n */\nexport const ListOrderFieldSchema = z.enum(['keys', 'created_at', 'updated_at']);\n\n/**\n * Enum representing possible fields to order by.\n */\nexport type ListOrderField = 'keys' | 'updated_at' | 'created_at';\n\n/**\n * @see ListOrder\n */\nexport const ListOrderSchema = z\n .object({\n desc: z.boolean(),\n field: ListOrderFieldSchema\n })\n .strict();\n\n/**\n * Ordering strategy for listing documents.\n */\nexport interface ListOrder {\n desc: boolean;\n field: ListOrderField;\n}\n\n/**\n * @see ListParams\n */\nexport const ListParamsSchema = z\n .object({\n matcher: ListMatcherSchema.optional(),\n paginate: ListPaginateSchema.optional(),\n order: ListOrderSchema.optional(),\n owner: RawUserIdSchema.optional()\n })\n .strict();\n\n/**\n * Full set of listing parameters.\n */\nexport interface ListParams {\n matcher?: ListMatcher;\n paginate?: ListPaginate;\n order?: ListOrder;\n owner?: RawUserId;\n}\n\n/**\n * Represents a list result.\n *\n * @template T - The type of the data returned per item.\n * @see JsListResults\n */\nexport const createListResultsSchema = <T extends z.ZodTypeAny>(itemData: T) =>\n z\n .object({\n items: z.array(z.tuple([KeySchema, itemData])),\n items_length: z.bigint(),\n items_page: z.bigint().optional(),\n matches_length: z.bigint(),\n matches_pages: z.bigint().optional()\n })\n .strict();\n\n/**\n * List results, parameterized by type of returned item.\n */\nexport interface ListResults<T> {\n items: [Key, T][];\n items_length: bigint;\n items_page?: bigint;\n matches_length: bigint;\n matches_pages?: bigint;\n}\n"],
5
- "mappings": "sDAAA,UAAYA,MAAO,SAMZ,IAAMC,EAAoB,SAAO,EAY3BC,EAAkB,SAAO,EAYzBC,EAAkBC,EAYlBC,EAAeC,EAYfC,EAAqB,SAAO,EAU5BC,EAAc,SAAO,EAUrBC,EAAsB,SAAO,EAAE,IAAI,IAAI,EC1EpD,UAAYC,MAAO,SAgBZ,IAAMC,EAAgBC,EAYhBC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7C,aAAgB,SAAO,EACvB,WAAc,SAAO,EAAE,SAAS,EAChC,eAAkB,SAAO,EACzB,cAAiB,SAAO,EAAE,SAAS,CACrC,CAAC,EACA,OAAO",
6
- "names": ["z", "TimestampSchema", "VersionSchema", "RawUserIdSchema", "RawPrincipalSchema", "UserIdSchema", "PrincipalSchema", "CollectionSchema", "KeySchema", "DescriptionSchema", "z", "RawDataSchema", "Uint8ArraySchema", "DocSchema", "RawUserIdSchema", "DescriptionSchema", "TimestampSchema", "VersionSchema", "OptionDocSchema", "SetDocSchema", "DelDocSchema", "z", "HeaderFieldSchema", "HeaderFieldsSchema", "BlobSchema", "Uint8ArraySchema", "BlobOrKeySchema", "HashSchema", "val", "AssetKeySchema", "CollectionSchema", "RawUserIdSchema", "DescriptionSchema", "AssetEncodingSchema", "TimestampSchema", "AssetEncodingNoContentSchema", "EncodingTypeSchema", "AssetSchema", "VersionSchema", "AssetNoContentSchema", "ReferenceIdSchema", "BatchSchema", "ChunkIdSchema", "BatchIdSchema", "CommitBatchSchema", "FullPathSchema", "OptionAssetSchema", "z", "TimestampMatcherSchema", "TimestampSchema", "ListMatcherSchema", "KeySchema", "DescriptionSchema", "ListPaginateSchema", "ListOrderFieldSchema", "ListOrderSchema", "ListParamsSchema", "RawUserIdSchema", "createListResultsSchema", "itemData"]
7
- }