@contractspec/lib.files 1.44.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/contracts/index.ts"],"sourcesContent":["import { ScalarTypeEnum, defineSchemaModel } from '@contractspec/lib.schema';\nimport { defineCommand, defineQuery } from '@contractspec/lib.contracts';\n\nconst OWNERS = ['platform.files'] as const;\n\n// ============ Schema Models ============\n\nexport const FileModel = defineSchemaModel({\n name: 'File',\n description: 'Represents an uploaded file',\n fields: {\n id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n mimeType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n size: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n storageProvider: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: false,\n },\n storagePath: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n checksum: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n isPublic: { type: ScalarTypeEnum.Boolean(), isOptional: false },\n ownerId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n metadata: { type: ScalarTypeEnum.JSON(), isOptional: true },\n width: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },\n height: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },\n createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n updatedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n },\n});\n\nexport const FileVersionModel = defineSchemaModel({\n name: 'FileVersion',\n description: 'Represents a file version',\n fields: {\n id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n fileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n version: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n size: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n storagePath: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n checksum: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n comment: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n createdBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n },\n});\n\nexport const AttachmentModel = defineSchemaModel({\n name: 'Attachment',\n description: 'Represents an attachment',\n fields: {\n id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n fileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n entityType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n entityId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n attachmentType: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: true,\n },\n name: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n order: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n metadata: { type: ScalarTypeEnum.JSON(), isOptional: true },\n createdBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n file: { type: FileModel, isOptional: true },\n },\n});\n\nexport const PresignedUrlModel = defineSchemaModel({\n name: 'PresignedUrl',\n description: 'A presigned URL for file operations',\n fields: {\n url: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n fields: { type: ScalarTypeEnum.JSON(), isOptional: true },\n expiresAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n fileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n sessionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n },\n});\n\n// ============ Input/Output Models ============\n\nconst UploadFileInput = defineSchemaModel({\n name: 'UploadFileInput',\n description: 'Input for uploading a file',\n fields: {\n name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n mimeType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n size: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n content: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }, // Base64 encoded\n orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n isPublic: { type: ScalarTypeEnum.Boolean(), isOptional: true },\n metadata: { type: ScalarTypeEnum.JSON(), isOptional: true },\n tags: { type: ScalarTypeEnum.JSON(), isOptional: true },\n },\n});\n\nconst UpdateFileInput = defineSchemaModel({\n name: 'UpdateFileInput',\n description: 'Input for updating a file',\n fields: {\n fileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n name: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n isPublic: { type: ScalarTypeEnum.Boolean(), isOptional: true },\n metadata: { type: ScalarTypeEnum.JSON(), isOptional: true },\n tags: { type: ScalarTypeEnum.JSON(), isOptional: true },\n },\n});\n\nconst DeleteFileInput = defineSchemaModel({\n name: 'DeleteFileInput',\n description: 'Input for deleting a file',\n fields: {\n fileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nconst GetFileInput = defineSchemaModel({\n name: 'GetFileInput',\n description: 'Input for getting a file',\n fields: {\n fileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nconst ListFilesInput = defineSchemaModel({\n name: 'ListFilesInput',\n description: 'Input for listing files',\n fields: {\n orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n ownerId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n mimeType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n status: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n tags: { type: ScalarTypeEnum.JSON(), isOptional: true },\n limit: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },\n offset: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },\n },\n});\n\nconst ListFilesOutput = defineSchemaModel({\n name: 'ListFilesOutput',\n description: 'Output for listing files',\n fields: {\n files: { type: FileModel, isArray: true, isOptional: false },\n total: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n },\n});\n\nconst GetDownloadUrlInput = defineSchemaModel({\n name: 'GetDownloadUrlInput',\n description: 'Input for getting a download URL',\n fields: {\n fileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n expiresInSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },\n },\n});\n\nconst CreateVersionInput = defineSchemaModel({\n name: 'CreateVersionInput',\n description: 'Input for creating a file version',\n fields: {\n fileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n content: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }, // Base64 encoded\n comment: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n },\n});\n\nconst GetVersionsInput = defineSchemaModel({\n name: 'GetVersionsInput',\n description: 'Input for getting file versions',\n fields: {\n fileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n limit: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },\n offset: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },\n },\n});\n\nconst GetVersionsOutput = defineSchemaModel({\n name: 'GetVersionsOutput',\n description: 'Output for getting file versions',\n fields: {\n versions: { type: FileVersionModel, isArray: true, isOptional: false },\n total: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n },\n});\n\nconst AttachFileInput = defineSchemaModel({\n name: 'AttachFileInput',\n description: 'Input for attaching a file to an entity',\n fields: {\n fileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n entityType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n entityId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n attachmentType: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: true,\n },\n name: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n order: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },\n metadata: { type: ScalarTypeEnum.JSON(), isOptional: true },\n },\n});\n\nconst DetachFileInput = defineSchemaModel({\n name: 'DetachFileInput',\n description: 'Input for detaching a file',\n fields: {\n attachmentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nconst ListAttachmentsInput = defineSchemaModel({\n name: 'ListAttachmentsInput',\n description: 'Input for listing attachments',\n fields: {\n entityType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n entityId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n attachmentType: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: true,\n },\n },\n});\n\nconst ListAttachmentsOutput = defineSchemaModel({\n name: 'ListAttachmentsOutput',\n description: 'Output for listing attachments',\n fields: {\n attachments: { type: AttachmentModel, isArray: true, isOptional: false },\n total: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n },\n});\n\nconst CreatePresignedUrlInput = defineSchemaModel({\n name: 'CreatePresignedUrlInput',\n description: 'Input for creating a presigned upload URL',\n fields: {\n fileName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n mimeType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n size: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n expiresInSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },\n },\n});\n\nconst SuccessOutput = defineSchemaModel({\n name: 'SuccessOutput',\n description: 'Generic success output',\n fields: {\n success: { type: ScalarTypeEnum.Boolean(), isOptional: false },\n },\n});\n\n// ============ Contracts ============\n\n/**\n * Upload a file.\n */\nexport const UploadFileContract = defineCommand({\n meta: {\n key: 'file.upload',\n version: 1,\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['files', 'upload'],\n description: 'Upload a new file.',\n goal: 'Store a file and create a file record.',\n context: 'Called when uploading files directly.',\n },\n io: {\n input: UploadFileInput,\n output: FileModel,\n errors: {\n FILE_TOO_LARGE: {\n description: 'File exceeds size limit',\n http: 413,\n gqlCode: 'FILE_TOO_LARGE',\n when: 'File size exceeds configured limit',\n },\n INVALID_MIME_TYPE: {\n description: 'MIME type not allowed',\n http: 415,\n gqlCode: 'INVALID_MIME_TYPE',\n when: 'File type is not in allowed list',\n },\n },\n },\n policy: {\n auth: 'user',\n },\n});\n\n/**\n * Update a file.\n */\nexport const UpdateFileContract = defineCommand({\n meta: {\n key: 'file.update',\n version: 1,\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['files', 'update'],\n description: 'Update file metadata.',\n goal: 'Modify file properties without replacing content.',\n context: 'Called when renaming or updating file metadata.',\n },\n io: {\n input: UpdateFileInput,\n output: FileModel,\n errors: {\n FILE_NOT_FOUND: {\n description: 'File does not exist',\n http: 404,\n gqlCode: 'FILE_NOT_FOUND',\n when: 'File ID is invalid',\n },\n },\n },\n policy: {\n auth: 'user',\n },\n});\n\n/**\n * Delete a file.\n */\nexport const DeleteFileContract = defineCommand({\n meta: {\n key: 'file.delete',\n version: 1,\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['files', 'delete'],\n description: 'Delete a file.',\n goal: 'Remove a file and all its versions and attachments.',\n context: 'Called when removing a file permanently.',\n },\n io: {\n input: DeleteFileInput,\n output: SuccessOutput,\n errors: {\n FILE_NOT_FOUND: {\n description: 'File does not exist',\n http: 404,\n gqlCode: 'FILE_NOT_FOUND',\n when: 'File ID is invalid',\n },\n },\n },\n policy: {\n auth: 'user',\n },\n});\n\n/**\n * Get a file by ID.\n */\nexport const GetFileContract = defineQuery({\n meta: {\n key: 'file.get',\n version: 1,\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['files', 'get'],\n description: 'Get a file by ID.',\n goal: 'Retrieve file metadata.',\n context: 'Called to inspect file details.',\n },\n io: {\n input: GetFileInput,\n output: FileModel,\n errors: {\n FILE_NOT_FOUND: {\n description: 'File does not exist',\n http: 404,\n gqlCode: 'FILE_NOT_FOUND',\n when: 'File ID is invalid',\n },\n },\n },\n policy: {\n auth: 'user',\n },\n});\n\n/**\n * List files.\n */\nexport const ListFilesContract = defineQuery({\n meta: {\n key: 'file.list',\n version: 1,\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['files', 'list'],\n description: 'List files with filtering.',\n goal: 'Browse uploaded files.',\n context: 'Called to browse file library.',\n },\n io: {\n input: ListFilesInput,\n output: ListFilesOutput,\n },\n policy: {\n auth: 'user',\n },\n});\n\n/**\n * Get download URL.\n */\nexport const GetDownloadUrlContract = defineQuery({\n meta: {\n key: 'file.downloadUrl',\n version: 1,\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['files', 'download'],\n description: 'Get a presigned download URL.',\n goal: 'Generate a temporary URL for downloading.',\n context: 'Called when user wants to download a file.',\n },\n io: {\n input: GetDownloadUrlInput,\n output: PresignedUrlModel,\n errors: {\n FILE_NOT_FOUND: {\n description: 'File does not exist',\n http: 404,\n gqlCode: 'FILE_NOT_FOUND',\n when: 'File ID is invalid',\n },\n },\n },\n policy: {\n auth: 'user',\n },\n});\n\n/**\n * Create a file version.\n */\nexport const CreateVersionContract = defineCommand({\n meta: {\n key: 'file.version.create',\n version: 1,\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['files', 'version', 'create'],\n description: 'Create a new version of a file.',\n goal: 'Upload a new version while preserving history.',\n context: 'Called when updating a document.',\n },\n io: {\n input: CreateVersionInput,\n output: FileVersionModel,\n errors: {\n FILE_NOT_FOUND: {\n description: 'File does not exist',\n http: 404,\n gqlCode: 'FILE_NOT_FOUND',\n when: 'File ID is invalid',\n },\n },\n },\n policy: {\n auth: 'user',\n },\n});\n\n/**\n * Get file versions.\n */\nexport const GetVersionsContract = defineQuery({\n meta: {\n key: 'file.version.list',\n version: 1,\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['files', 'version', 'list'],\n description: 'Get file version history.',\n goal: 'View all versions of a file.',\n context: 'Called to browse file history.',\n },\n io: {\n input: GetVersionsInput,\n output: GetVersionsOutput,\n errors: {\n FILE_NOT_FOUND: {\n description: 'File does not exist',\n http: 404,\n gqlCode: 'FILE_NOT_FOUND',\n when: 'File ID is invalid',\n },\n },\n },\n policy: {\n auth: 'user',\n },\n});\n\n/**\n * Attach a file to an entity.\n */\nexport const AttachFileContract = defineCommand({\n meta: {\n key: 'attachment.attach',\n version: 1,\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['files', 'attachment', 'attach'],\n description: 'Attach a file to an entity.',\n goal: 'Link a file to a business entity.',\n context: 'Called when associating files with entities.',\n },\n io: {\n input: AttachFileInput,\n output: AttachmentModel,\n errors: {\n FILE_NOT_FOUND: {\n description: 'File does not exist',\n http: 404,\n gqlCode: 'FILE_NOT_FOUND',\n when: 'File ID is invalid',\n },\n ATTACHMENT_EXISTS: {\n description: 'Attachment already exists',\n http: 409,\n gqlCode: 'ATTACHMENT_EXISTS',\n when: 'File is already attached to this entity',\n },\n },\n },\n policy: {\n auth: 'user',\n },\n});\n\n/**\n * Detach a file from an entity.\n */\nexport const DetachFileContract = defineCommand({\n meta: {\n key: 'attachment.detach',\n version: 1,\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['files', 'attachment', 'detach'],\n description: 'Detach a file from an entity.',\n goal: 'Remove a file association.',\n context: 'Called when removing file from entity.',\n },\n io: {\n input: DetachFileInput,\n output: SuccessOutput,\n errors: {\n ATTACHMENT_NOT_FOUND: {\n description: 'Attachment does not exist',\n http: 404,\n gqlCode: 'ATTACHMENT_NOT_FOUND',\n when: 'Attachment ID is invalid',\n },\n },\n },\n policy: {\n auth: 'user',\n },\n});\n\n/**\n * List attachments for an entity.\n */\nexport const ListAttachmentsContract = defineQuery({\n meta: {\n key: 'attachment.list',\n version: 1,\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['files', 'attachment', 'list'],\n description: 'List attachments for an entity.',\n goal: 'Get all files attached to an entity.',\n context: 'Called to display attached files.',\n },\n io: {\n input: ListAttachmentsInput,\n output: ListAttachmentsOutput,\n },\n policy: {\n auth: 'user',\n },\n});\n\n/**\n * Create a presigned upload URL.\n */\nexport const CreatePresignedUrlContract = defineCommand({\n meta: {\n key: 'file.presignedUrl.create',\n version: 1,\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['files', 'presigned', 'upload'],\n description: 'Create a presigned URL for direct upload.',\n goal: 'Enable direct-to-storage uploads.',\n context: 'Called for large file uploads.',\n },\n io: {\n input: CreatePresignedUrlInput,\n output: PresignedUrlModel,\n errors: {\n FILE_TOO_LARGE: {\n description: 'File exceeds size limit',\n http: 413,\n gqlCode: 'FILE_TOO_LARGE',\n when: 'Requested file size exceeds limit',\n },\n INVALID_MIME_TYPE: {\n description: 'MIME type not allowed',\n http: 415,\n gqlCode: 'INVALID_MIME_TYPE',\n when: 'File type is not in allowed list',\n },\n },\n },\n policy: {\n auth: 'user',\n },\n});\n"],"mappings":";;;;AAGA,MAAM,SAAS,CAAC,iBAAiB;AAIjC,MAAa,YAAY,kBAAkB;CACzC,MAAM;CACN,aAAa;CACb,QAAQ;EACN,IAAI;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACjE,MAAM;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACnE,UAAU;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACvE,MAAM;GAAE,MAAM,eAAe,cAAc;GAAE,YAAY;GAAO;EAChE,iBAAiB;GACf,MAAM,eAAe,iBAAiB;GACtC,YAAY;GACb;EACD,aAAa;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EAC1E,UAAU;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAM;EACtE,QAAQ;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACrE,UAAU;GAAE,MAAM,eAAe,SAAS;GAAE,YAAY;GAAO;EAC/D,SAAS;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACtE,OAAO;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAM;EACnE,UAAU;GAA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D,QAAQ,EACN,MAAM,QACP;CACF,CAAC;;;;AAKF,MAAa,6BAA6B,cAAc;CACtD,MAAM;EACJ,KAAK;EACL,SAAS;EACT,WAAW;EACX,QAAQ,CAAC,GAAG,OAAO;EACnB,MAAM;GAAC;GAAS;GAAa;GAAS;EACtC,aAAa;EACb,MAAM;EACN,SAAS;EACV;CACD,IAAI;EACF,OAAO;EACP,QAAQ;EACR,QAAQ;GACN,gBAAgB;IACd,aAAa;IACb,MAAM;IACN,SAAS;IACT,MAAM;IACP;GACD,mBAAmB;IACjB,aAAa;IACb,MAAM;IACN,SAAS;IACT,MAAM;IACP;GACF;EACF;CACD,QAAQ,EACN,MAAM,QACP;CACF,CAAC"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,71 @@
1
+ import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
2
+
3
+ //#region src/docs/files.docblock.ts
4
+ registerDocBlocks([{
5
+ id: "docs.files.attachments",
6
+ title: "Files, Versions & Attachments",
7
+ summary: "Spec-first file management with storage adapters, versioning, presigned URLs, and polymorphic attachments for any entity.",
8
+ kind: "reference",
9
+ visibility: "public",
10
+ route: "/docs/files/attachments",
11
+ tags: [
12
+ "files",
13
+ "attachments",
14
+ "storage",
15
+ "versions"
16
+ ],
17
+ body: `## Capabilities
18
+
19
+ - **Entities**: File, FileVersion, Attachment, UploadSession with retention, checksum, ACLs.
20
+ - **Contracts**: upload/update/delete/list/get files; presigned upload/download; version create/list; attach/detach/list attachments.
21
+ - **Storage**: pluggable adapters (Local, S3 placeholder + interface), in-memory for tests.
22
+ - **Events**: file.uploaded/deleted, attachment.added/removed (see events export).
23
+
24
+ ## Usage
25
+
26
+ 1) Compose schema
27
+ - Include \`filesSchemaContribution\` in your schema composition.
28
+
29
+ 2) Register contracts/events
30
+ - Import contracts and events from \`@contractspec/lib.files\` in your spec registry.
31
+
32
+ 3) Wire storage
33
+ - Provide a \`StorageAdapter\` implementation (local/in-memory or S3 via custom impl).
34
+ - Use \`createStorageAdapter\` with config to instantiate.
35
+
36
+ 4) Attach to domain entities
37
+ - Use \`attachment.attach\` with \`entityType/entityId\` to link files to deals, orders, runs, etc.
38
+
39
+ ## Example
40
+
41
+ \`\`\`ts
42
+ import {
43
+ UploadFileContract,
44
+ AttachFileContract,
45
+ InMemoryStorageAdapter,
46
+ } from '@contractspec/lib.files';
47
+
48
+ // storage
49
+ const storage = new InMemoryStorageAdapter();
50
+
51
+ // upload
52
+ const file = await storage.upload({
53
+ path: 'org-1/reports/r1.pdf',
54
+ content: Buffer.from(pdfBytes),
55
+ mimeType: 'application/pdf',
56
+ });
57
+
58
+ // attach
59
+ await AttachFileContract; // register in spec to enable attach flows
60
+ \`\`\`,
61
+
62
+ ## Guardrails
63
+
64
+ - Enforce size/MIME limits in your handlers; avoid storing PII in paths.
65
+ - Keep \`orgId\` scoped for multi-tenant isolation; prefer presigned URLs for public delivery.
66
+ - Persist checksums for integrity; emit audit + events for access/retention changes.
67
+ `
68
+ }]);
69
+
70
+ //#endregion
71
+ //# sourceMappingURL=files.docblock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.docblock.js","names":[],"sources":["../../src/docs/files.docblock.ts"],"sourcesContent":["import type { DocBlock } from '@contractspec/lib.contracts/docs';\nimport { registerDocBlocks } from '@contractspec/lib.contracts/docs';\n\nconst filesDocBlocks: DocBlock[] = [\n {\n id: 'docs.files.attachments',\n title: 'Files, Versions & Attachments',\n summary:\n 'Spec-first file management with storage adapters, versioning, presigned URLs, and polymorphic attachments for any entity.',\n kind: 'reference',\n visibility: 'public',\n route: '/docs/files/attachments',\n tags: ['files', 'attachments', 'storage', 'versions'],\n body: `## Capabilities\n\n- **Entities**: File, FileVersion, Attachment, UploadSession with retention, checksum, ACLs.\n- **Contracts**: upload/update/delete/list/get files; presigned upload/download; version create/list; attach/detach/list attachments.\n- **Storage**: pluggable adapters (Local, S3 placeholder + interface), in-memory for tests.\n- **Events**: file.uploaded/deleted, attachment.added/removed (see events export).\n\n## Usage\n\n1) Compose schema\n- Include \\`filesSchemaContribution\\` in your schema composition.\n\n2) Register contracts/events\n- Import contracts and events from \\`@contractspec/lib.files\\` in your spec registry.\n\n3) Wire storage\n- Provide a \\`StorageAdapter\\` implementation (local/in-memory or S3 via custom impl).\n- Use \\`createStorageAdapter\\` with config to instantiate.\n\n4) Attach to domain entities\n- Use \\`attachment.attach\\` with \\`entityType/entityId\\` to link files to deals, orders, runs, etc.\n\n## Example\n\n${'```'}ts\nimport {\n UploadFileContract,\n AttachFileContract,\n InMemoryStorageAdapter,\n} from '@contractspec/lib.files';\n\n// storage\nconst storage = new InMemoryStorageAdapter();\n\n// upload\nconst file = await storage.upload({\n path: 'org-1/reports/r1.pdf',\n content: Buffer.from(pdfBytes),\n mimeType: 'application/pdf',\n});\n\n// attach\nawait AttachFileContract; // register in spec to enable attach flows\n${'```'},\n\n## Guardrails\n\n- Enforce size/MIME limits in your handlers; avoid storing PII in paths.\n- Keep \\`orgId\\` scoped for multi-tenant isolation; prefer presigned URLs for public delivery.\n- Persist checksums for integrity; emit audit + events for access/retention changes.\n`,\n },\n];\n\nregisterDocBlocks(filesDocBlocks);\n"],"mappings":";;;AAmEA,kBAhEmC,CACjC;CACE,IAAI;CACJ,OAAO;CACP,SACE;CACF,MAAM;CACN,YAAY;CACZ,OAAO;CACP,MAAM;EAAC;EAAS;EAAe;EAAW;EAAW;CACrD,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDP,CACF,CAEgC"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ import "./files.docblock.js";
@@ -0,0 +1,169 @@
1
+ import * as _contractspec_lib_schema404 from "@contractspec/lib.schema";
2
+ import { ModuleSchemaContribution } from "@contractspec/lib.schema";
3
+
4
+ //#region src/entities/index.d.ts
5
+ /**
6
+ * Storage provider enum.
7
+ */
8
+ declare const StorageProviderEnum: _contractspec_lib_schema404.EntityEnumDef;
9
+ /**
10
+ * File status enum.
11
+ */
12
+ declare const FileStatusEnum: _contractspec_lib_schema404.EntityEnumDef;
13
+ /**
14
+ * File entity - represents an uploaded file.
15
+ */
16
+ declare const FileEntity: _contractspec_lib_schema404.EntitySpec<{
17
+ id: _contractspec_lib_schema404.EntityScalarField;
18
+ name: _contractspec_lib_schema404.EntityScalarField;
19
+ mimeType: _contractspec_lib_schema404.EntityScalarField;
20
+ size: _contractspec_lib_schema404.EntityScalarField;
21
+ storageProvider: _contractspec_lib_schema404.EntityEnumField;
22
+ storagePath: _contractspec_lib_schema404.EntityScalarField;
23
+ storageKey: _contractspec_lib_schema404.EntityScalarField;
24
+ checksum: _contractspec_lib_schema404.EntityScalarField;
25
+ etag: _contractspec_lib_schema404.EntityScalarField;
26
+ status: _contractspec_lib_schema404.EntityEnumField;
27
+ isPublic: _contractspec_lib_schema404.EntityScalarField;
28
+ expiresAt: _contractspec_lib_schema404.EntityScalarField;
29
+ ownerId: _contractspec_lib_schema404.EntityScalarField;
30
+ orgId: _contractspec_lib_schema404.EntityScalarField;
31
+ metadata: _contractspec_lib_schema404.EntityScalarField;
32
+ tags: _contractspec_lib_schema404.EntityScalarField;
33
+ width: _contractspec_lib_schema404.EntityScalarField;
34
+ height: _contractspec_lib_schema404.EntityScalarField;
35
+ createdAt: _contractspec_lib_schema404.EntityScalarField;
36
+ updatedAt: _contractspec_lib_schema404.EntityScalarField;
37
+ versions: _contractspec_lib_schema404.EntityRelationField;
38
+ attachments: _contractspec_lib_schema404.EntityRelationField;
39
+ }>;
40
+ /**
41
+ * FileVersion entity - version history for files.
42
+ */
43
+ declare const FileVersionEntity: _contractspec_lib_schema404.EntitySpec<{
44
+ id: _contractspec_lib_schema404.EntityScalarField;
45
+ fileId: _contractspec_lib_schema404.EntityScalarField;
46
+ version: _contractspec_lib_schema404.EntityScalarField;
47
+ size: _contractspec_lib_schema404.EntityScalarField;
48
+ storagePath: _contractspec_lib_schema404.EntityScalarField;
49
+ checksum: _contractspec_lib_schema404.EntityScalarField;
50
+ comment: _contractspec_lib_schema404.EntityScalarField;
51
+ changes: _contractspec_lib_schema404.EntityScalarField;
52
+ createdBy: _contractspec_lib_schema404.EntityScalarField;
53
+ createdAt: _contractspec_lib_schema404.EntityScalarField;
54
+ file: _contractspec_lib_schema404.EntityRelationField;
55
+ }>;
56
+ /**
57
+ * Attachment entity - polymorphic link between files and entities.
58
+ */
59
+ declare const AttachmentEntity: _contractspec_lib_schema404.EntitySpec<{
60
+ id: _contractspec_lib_schema404.EntityScalarField;
61
+ fileId: _contractspec_lib_schema404.EntityScalarField;
62
+ entityType: _contractspec_lib_schema404.EntityScalarField;
63
+ entityId: _contractspec_lib_schema404.EntityScalarField;
64
+ attachmentType: _contractspec_lib_schema404.EntityScalarField;
65
+ name: _contractspec_lib_schema404.EntityScalarField;
66
+ description: _contractspec_lib_schema404.EntityScalarField;
67
+ order: _contractspec_lib_schema404.EntityScalarField;
68
+ metadata: _contractspec_lib_schema404.EntityScalarField;
69
+ createdBy: _contractspec_lib_schema404.EntityScalarField;
70
+ createdAt: _contractspec_lib_schema404.EntityScalarField;
71
+ updatedAt: _contractspec_lib_schema404.EntityScalarField;
72
+ file: _contractspec_lib_schema404.EntityRelationField;
73
+ }>;
74
+ /**
75
+ * UploadSession entity - tracks multipart uploads.
76
+ */
77
+ declare const UploadSessionEntity: _contractspec_lib_schema404.EntitySpec<{
78
+ id: _contractspec_lib_schema404.EntityScalarField;
79
+ fileName: _contractspec_lib_schema404.EntityScalarField;
80
+ mimeType: _contractspec_lib_schema404.EntityScalarField;
81
+ totalSize: _contractspec_lib_schema404.EntityScalarField;
82
+ uploadId: _contractspec_lib_schema404.EntityScalarField;
83
+ uploadedBytes: _contractspec_lib_schema404.EntityScalarField;
84
+ uploadedParts: _contractspec_lib_schema404.EntityScalarField;
85
+ status: _contractspec_lib_schema404.EntityScalarField;
86
+ error: _contractspec_lib_schema404.EntityScalarField;
87
+ fileId: _contractspec_lib_schema404.EntityScalarField;
88
+ ownerId: _contractspec_lib_schema404.EntityScalarField;
89
+ orgId: _contractspec_lib_schema404.EntityScalarField;
90
+ expiresAt: _contractspec_lib_schema404.EntityScalarField;
91
+ createdAt: _contractspec_lib_schema404.EntityScalarField;
92
+ updatedAt: _contractspec_lib_schema404.EntityScalarField;
93
+ }>;
94
+ /**
95
+ * All file entities for schema composition.
96
+ */
97
+ declare const fileEntities: (_contractspec_lib_schema404.EntitySpec<{
98
+ id: _contractspec_lib_schema404.EntityScalarField;
99
+ name: _contractspec_lib_schema404.EntityScalarField;
100
+ mimeType: _contractspec_lib_schema404.EntityScalarField;
101
+ size: _contractspec_lib_schema404.EntityScalarField;
102
+ storageProvider: _contractspec_lib_schema404.EntityEnumField;
103
+ storagePath: _contractspec_lib_schema404.EntityScalarField;
104
+ storageKey: _contractspec_lib_schema404.EntityScalarField;
105
+ checksum: _contractspec_lib_schema404.EntityScalarField;
106
+ etag: _contractspec_lib_schema404.EntityScalarField;
107
+ status: _contractspec_lib_schema404.EntityEnumField;
108
+ isPublic: _contractspec_lib_schema404.EntityScalarField;
109
+ expiresAt: _contractspec_lib_schema404.EntityScalarField;
110
+ ownerId: _contractspec_lib_schema404.EntityScalarField;
111
+ orgId: _contractspec_lib_schema404.EntityScalarField;
112
+ metadata: _contractspec_lib_schema404.EntityScalarField;
113
+ tags: _contractspec_lib_schema404.EntityScalarField;
114
+ width: _contractspec_lib_schema404.EntityScalarField;
115
+ height: _contractspec_lib_schema404.EntityScalarField;
116
+ createdAt: _contractspec_lib_schema404.EntityScalarField;
117
+ updatedAt: _contractspec_lib_schema404.EntityScalarField;
118
+ versions: _contractspec_lib_schema404.EntityRelationField;
119
+ attachments: _contractspec_lib_schema404.EntityRelationField;
120
+ }> | _contractspec_lib_schema404.EntitySpec<{
121
+ id: _contractspec_lib_schema404.EntityScalarField;
122
+ fileId: _contractspec_lib_schema404.EntityScalarField;
123
+ version: _contractspec_lib_schema404.EntityScalarField;
124
+ size: _contractspec_lib_schema404.EntityScalarField;
125
+ storagePath: _contractspec_lib_schema404.EntityScalarField;
126
+ checksum: _contractspec_lib_schema404.EntityScalarField;
127
+ comment: _contractspec_lib_schema404.EntityScalarField;
128
+ changes: _contractspec_lib_schema404.EntityScalarField;
129
+ createdBy: _contractspec_lib_schema404.EntityScalarField;
130
+ createdAt: _contractspec_lib_schema404.EntityScalarField;
131
+ file: _contractspec_lib_schema404.EntityRelationField;
132
+ }> | _contractspec_lib_schema404.EntitySpec<{
133
+ id: _contractspec_lib_schema404.EntityScalarField;
134
+ fileId: _contractspec_lib_schema404.EntityScalarField;
135
+ entityType: _contractspec_lib_schema404.EntityScalarField;
136
+ entityId: _contractspec_lib_schema404.EntityScalarField;
137
+ attachmentType: _contractspec_lib_schema404.EntityScalarField;
138
+ name: _contractspec_lib_schema404.EntityScalarField;
139
+ description: _contractspec_lib_schema404.EntityScalarField;
140
+ order: _contractspec_lib_schema404.EntityScalarField;
141
+ metadata: _contractspec_lib_schema404.EntityScalarField;
142
+ createdBy: _contractspec_lib_schema404.EntityScalarField;
143
+ createdAt: _contractspec_lib_schema404.EntityScalarField;
144
+ updatedAt: _contractspec_lib_schema404.EntityScalarField;
145
+ file: _contractspec_lib_schema404.EntityRelationField;
146
+ }> | _contractspec_lib_schema404.EntitySpec<{
147
+ id: _contractspec_lib_schema404.EntityScalarField;
148
+ fileName: _contractspec_lib_schema404.EntityScalarField;
149
+ mimeType: _contractspec_lib_schema404.EntityScalarField;
150
+ totalSize: _contractspec_lib_schema404.EntityScalarField;
151
+ uploadId: _contractspec_lib_schema404.EntityScalarField;
152
+ uploadedBytes: _contractspec_lib_schema404.EntityScalarField;
153
+ uploadedParts: _contractspec_lib_schema404.EntityScalarField;
154
+ status: _contractspec_lib_schema404.EntityScalarField;
155
+ error: _contractspec_lib_schema404.EntityScalarField;
156
+ fileId: _contractspec_lib_schema404.EntityScalarField;
157
+ ownerId: _contractspec_lib_schema404.EntityScalarField;
158
+ orgId: _contractspec_lib_schema404.EntityScalarField;
159
+ expiresAt: _contractspec_lib_schema404.EntityScalarField;
160
+ createdAt: _contractspec_lib_schema404.EntityScalarField;
161
+ updatedAt: _contractspec_lib_schema404.EntityScalarField;
162
+ }>)[];
163
+ /**
164
+ * Module schema contribution for files.
165
+ */
166
+ declare const filesSchemaContribution: ModuleSchemaContribution;
167
+ //#endregion
168
+ export { AttachmentEntity, FileEntity, FileStatusEnum, FileVersionEntity, StorageProviderEnum, UploadSessionEntity, fileEntities, filesSchemaContribution };
169
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/entities/index.ts"],"sourcesContent":[],"mappings":";;;;;;;AAWa,cAAA,mBAKX,EAAA,2BAAA,CAL8B,aAK9B;AAKF;AAiBA;;cAjBa,gBAYX,2BAAA,CAZyB;;;;cAiBd,wCAAU;MA0FrB,2BAAA,CAAA;;;;;;;;;;;;;;;;sDA1FqB;EAAA,MAAA,+CAAA;EA+FV,SAAA,+CAwCX;EAAA,SAAA,+CAAA;;;;;;;cAxCW,+CAAiB;MAwC5B,2BAAA,CAAA;;;qDAxC4B;EAAA,WAAA,+CAAA;EA6CjB,QAAA,+CAwDX;EAAA,OAAA,+CAAA;;;;;;;;;cAxDW,8CAAgB;MAwD3B,2BAAA,CAAA;;;yDAxD2B;EAAA,cAAA,+CAAA;EA6DhB,IAAA,+CA0DX;EAAA,WAAA,+CAAA;;;;;;;;;;;cA1DW,iDAAmB;MA0D9B,2BAAA,CAAA;;;0DA1D8B;EAAA,QAAA,+CAAA;EA+DnB,aAAA,+CAKZ;EAAA,aAAA,+CAAA;;;;;;;;;;;;;cALY,2CAAY;MAKxB,2BAAA,CAAA;;;;;;;;qDALwB;EAAA,MAAA,6CAAA;;;;;;;;;;;;;;MAAA,2BAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUZ,SAAA,+CAIZ;;;;;;;;;;;;;;;;cAJY,yBAAyB"}
@@ -0,0 +1,265 @@
1
+ import { defineEntity, defineEntityEnum, field, index } from "@contractspec/lib.schema";
2
+
3
+ //#region src/entities/index.ts
4
+ /**
5
+ * Storage provider enum.
6
+ */
7
+ const StorageProviderEnum = defineEntityEnum({
8
+ name: "StorageProvider",
9
+ values: [
10
+ "LOCAL",
11
+ "S3",
12
+ "GCS",
13
+ "AZURE",
14
+ "CLOUDFLARE"
15
+ ],
16
+ schema: "lssm_files",
17
+ description: "Storage backend provider."
18
+ });
19
+ /**
20
+ * File status enum.
21
+ */
22
+ const FileStatusEnum = defineEntityEnum({
23
+ name: "FileStatus",
24
+ values: [
25
+ "PENDING",
26
+ "UPLOADED",
27
+ "PROCESSING",
28
+ "READY",
29
+ "ERROR",
30
+ "DELETED"
31
+ ],
32
+ schema: "lssm_files",
33
+ description: "File processing status."
34
+ });
35
+ /**
36
+ * File entity - represents an uploaded file.
37
+ */
38
+ const FileEntity = defineEntity({
39
+ name: "File",
40
+ description: "An uploaded file.",
41
+ schema: "lssm_files",
42
+ map: "file",
43
+ fields: {
44
+ id: field.id({ description: "Unique file identifier" }),
45
+ name: field.string({ description: "Original file name" }),
46
+ mimeType: field.string({ description: "MIME type" }),
47
+ size: field.int({ description: "File size in bytes" }),
48
+ storageProvider: field.enum("StorageProvider", {
49
+ default: "LOCAL",
50
+ description: "Storage backend"
51
+ }),
52
+ storagePath: field.string({ description: "Path in storage backend" }),
53
+ storageKey: field.string({
54
+ isOptional: true,
55
+ description: "Storage key/bucket"
56
+ }),
57
+ checksum: field.string({
58
+ isOptional: true,
59
+ description: "SHA-256 checksum"
60
+ }),
61
+ etag: field.string({
62
+ isOptional: true,
63
+ description: "Storage ETag"
64
+ }),
65
+ status: field.enum("FileStatus", {
66
+ default: "PENDING",
67
+ description: "File status"
68
+ }),
69
+ isPublic: field.boolean({
70
+ default: false,
71
+ description: "Whether file is publicly accessible"
72
+ }),
73
+ expiresAt: field.dateTime({
74
+ isOptional: true,
75
+ description: "Auto-delete timestamp"
76
+ }),
77
+ ownerId: field.string({ description: "User who uploaded" }),
78
+ orgId: field.string({
79
+ isOptional: true,
80
+ description: "Organization scope"
81
+ }),
82
+ metadata: field.json({
83
+ isOptional: true,
84
+ description: "Additional metadata"
85
+ }),
86
+ tags: field.json({
87
+ isOptional: true,
88
+ description: "Tags for categorization"
89
+ }),
90
+ width: field.int({
91
+ isOptional: true,
92
+ description: "Image width in pixels"
93
+ }),
94
+ height: field.int({
95
+ isOptional: true,
96
+ description: "Image height in pixels"
97
+ }),
98
+ createdAt: field.createdAt(),
99
+ updatedAt: field.updatedAt(),
100
+ versions: field.hasMany("FileVersion"),
101
+ attachments: field.hasMany("Attachment")
102
+ },
103
+ indexes: [
104
+ index.on(["ownerId"]),
105
+ index.on(["orgId"]),
106
+ index.on(["status"]),
107
+ index.on(["mimeType"]),
108
+ index.on(["storageProvider", "storagePath"])
109
+ ],
110
+ enums: [StorageProviderEnum, FileStatusEnum]
111
+ });
112
+ /**
113
+ * FileVersion entity - version history for files.
114
+ */
115
+ const FileVersionEntity = defineEntity({
116
+ name: "FileVersion",
117
+ description: "A version of a file.",
118
+ schema: "lssm_files",
119
+ map: "file_version",
120
+ fields: {
121
+ id: field.id({ description: "Unique version identifier" }),
122
+ fileId: field.foreignKey({ description: "Parent file" }),
123
+ version: field.int({ description: "Version number" }),
124
+ size: field.int({ description: "Version size in bytes" }),
125
+ storagePath: field.string({ description: "Path in storage backend" }),
126
+ checksum: field.string({
127
+ isOptional: true,
128
+ description: "SHA-256 checksum"
129
+ }),
130
+ comment: field.string({
131
+ isOptional: true,
132
+ description: "Version comment"
133
+ }),
134
+ changes: field.json({
135
+ isOptional: true,
136
+ description: "Change description"
137
+ }),
138
+ createdBy: field.string({ description: "User who created version" }),
139
+ createdAt: field.createdAt(),
140
+ file: field.belongsTo("File", ["fileId"], ["id"], { onDelete: "Cascade" })
141
+ },
142
+ indexes: [index.on(["fileId", "version"]), index.unique(["fileId", "version"], { name: "file_version_unique" })]
143
+ });
144
+ /**
145
+ * Attachment entity - polymorphic link between files and entities.
146
+ */
147
+ const AttachmentEntity = defineEntity({
148
+ name: "Attachment",
149
+ description: "Links a file to an entity.",
150
+ schema: "lssm_files",
151
+ map: "attachment",
152
+ fields: {
153
+ id: field.id({ description: "Unique attachment identifier" }),
154
+ fileId: field.foreignKey({ description: "Attached file" }),
155
+ entityType: field.string({ description: "Target entity type (deal, listing, etc.)" }),
156
+ entityId: field.string({ description: "Target entity ID" }),
157
+ attachmentType: field.string({
158
+ isOptional: true,
159
+ description: "Type of attachment (document, image, avatar, etc.)"
160
+ }),
161
+ name: field.string({
162
+ isOptional: true,
163
+ description: "Display name (overrides file name)"
164
+ }),
165
+ description: field.string({
166
+ isOptional: true,
167
+ description: "Attachment description"
168
+ }),
169
+ order: field.int({
170
+ default: 0,
171
+ description: "Display order"
172
+ }),
173
+ metadata: field.json({
174
+ isOptional: true,
175
+ description: "Attachment-specific metadata"
176
+ }),
177
+ createdBy: field.string({ description: "User who created attachment" }),
178
+ createdAt: field.createdAt(),
179
+ updatedAt: field.updatedAt(),
180
+ file: field.belongsTo("File", ["fileId"], ["id"], { onDelete: "Cascade" })
181
+ },
182
+ indexes: [
183
+ index.on(["entityType", "entityId"]),
184
+ index.on(["fileId"]),
185
+ index.on([
186
+ "entityType",
187
+ "entityId",
188
+ "attachmentType"
189
+ ]),
190
+ index.unique([
191
+ "fileId",
192
+ "entityType",
193
+ "entityId"
194
+ ], { name: "attachment_unique" })
195
+ ]
196
+ });
197
+ /**
198
+ * UploadSession entity - tracks multipart uploads.
199
+ */
200
+ const UploadSessionEntity = defineEntity({
201
+ name: "UploadSession",
202
+ description: "Tracks a multipart upload session.",
203
+ schema: "lssm_files",
204
+ map: "upload_session",
205
+ fields: {
206
+ id: field.id({ description: "Unique session identifier" }),
207
+ fileName: field.string({ description: "Target file name" }),
208
+ mimeType: field.string({ description: "Expected MIME type" }),
209
+ totalSize: field.int({ description: "Total file size" }),
210
+ uploadId: field.string({
211
+ isOptional: true,
212
+ description: "Storage upload ID"
213
+ }),
214
+ uploadedBytes: field.int({
215
+ default: 0,
216
+ description: "Bytes uploaded so far"
217
+ }),
218
+ uploadedParts: field.json({
219
+ isOptional: true,
220
+ description: "Completed part info"
221
+ }),
222
+ status: field.string({
223
+ default: "\"pending\"",
224
+ description: "Session status"
225
+ }),
226
+ error: field.string({
227
+ isOptional: true,
228
+ description: "Error message if failed"
229
+ }),
230
+ fileId: field.string({
231
+ isOptional: true,
232
+ description: "Resulting file ID"
233
+ }),
234
+ ownerId: field.string({ description: "User who initiated upload" }),
235
+ orgId: field.string({
236
+ isOptional: true,
237
+ description: "Organization scope"
238
+ }),
239
+ expiresAt: field.dateTime({ description: "Session expiry time" }),
240
+ createdAt: field.createdAt(),
241
+ updatedAt: field.updatedAt()
242
+ },
243
+ indexes: [index.on(["status", "expiresAt"]), index.on(["ownerId"])]
244
+ });
245
+ /**
246
+ * All file entities for schema composition.
247
+ */
248
+ const fileEntities = [
249
+ FileEntity,
250
+ FileVersionEntity,
251
+ AttachmentEntity,
252
+ UploadSessionEntity
253
+ ];
254
+ /**
255
+ * Module schema contribution for files.
256
+ */
257
+ const filesSchemaContribution = {
258
+ moduleId: "@contractspec/lib.files",
259
+ entities: fileEntities,
260
+ enums: [StorageProviderEnum, FileStatusEnum]
261
+ };
262
+
263
+ //#endregion
264
+ export { AttachmentEntity, FileEntity, FileStatusEnum, FileVersionEntity, StorageProviderEnum, UploadSessionEntity, fileEntities, filesSchemaContribution };
265
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["filesSchemaContribution: ModuleSchemaContribution"],"sources":["../../src/entities/index.ts"],"sourcesContent":["import {\n defineEntity,\n defineEntityEnum,\n field,\n index,\n} from '@contractspec/lib.schema';\nimport type { ModuleSchemaContribution } from '@contractspec/lib.schema';\n\n/**\n * Storage provider enum.\n */\nexport const StorageProviderEnum = defineEntityEnum({\n name: 'StorageProvider',\n values: ['LOCAL', 'S3', 'GCS', 'AZURE', 'CLOUDFLARE'] as const,\n schema: 'lssm_files',\n description: 'Storage backend provider.',\n});\n\n/**\n * File status enum.\n */\nexport const FileStatusEnum = defineEntityEnum({\n name: 'FileStatus',\n values: [\n 'PENDING',\n 'UPLOADED',\n 'PROCESSING',\n 'READY',\n 'ERROR',\n 'DELETED',\n ] as const,\n schema: 'lssm_files',\n description: 'File processing status.',\n});\n\n/**\n * File entity - represents an uploaded file.\n */\nexport const FileEntity = defineEntity({\n name: 'File',\n description: 'An uploaded file.',\n schema: 'lssm_files',\n map: 'file',\n fields: {\n id: field.id({ description: 'Unique file identifier' }),\n\n // File info\n name: field.string({ description: 'Original file name' }),\n mimeType: field.string({ description: 'MIME type' }),\n size: field.int({ description: 'File size in bytes' }),\n\n // Storage\n storageProvider: field.enum('StorageProvider', {\n default: 'LOCAL',\n description: 'Storage backend',\n }),\n storagePath: field.string({ description: 'Path in storage backend' }),\n storageKey: field.string({\n isOptional: true,\n description: 'Storage key/bucket',\n }),\n\n // Integrity\n checksum: field.string({\n isOptional: true,\n description: 'SHA-256 checksum',\n }),\n etag: field.string({ isOptional: true, description: 'Storage ETag' }),\n\n // Status\n status: field.enum('FileStatus', {\n default: 'PENDING',\n description: 'File status',\n }),\n\n // Access\n isPublic: field.boolean({\n default: false,\n description: 'Whether file is publicly accessible',\n }),\n expiresAt: field.dateTime({\n isOptional: true,\n description: 'Auto-delete timestamp',\n }),\n\n // Ownership\n ownerId: field.string({ description: 'User who uploaded' }),\n orgId: field.string({\n isOptional: true,\n description: 'Organization scope',\n }),\n\n // Metadata\n metadata: field.json({\n isOptional: true,\n description: 'Additional metadata',\n }),\n tags: field.json({\n isOptional: true,\n description: 'Tags for categorization',\n }),\n\n // Image-specific\n width: field.int({\n isOptional: true,\n description: 'Image width in pixels',\n }),\n height: field.int({\n isOptional: true,\n description: 'Image height in pixels',\n }),\n\n // Timestamps\n createdAt: field.createdAt(),\n updatedAt: field.updatedAt(),\n\n // Relations\n versions: field.hasMany('FileVersion'),\n attachments: field.hasMany('Attachment'),\n },\n indexes: [\n index.on(['ownerId']),\n index.on(['orgId']),\n index.on(['status']),\n index.on(['mimeType']),\n index.on(['storageProvider', 'storagePath']),\n ],\n enums: [StorageProviderEnum, FileStatusEnum],\n});\n\n/**\n * FileVersion entity - version history for files.\n */\nexport const FileVersionEntity = defineEntity({\n name: 'FileVersion',\n description: 'A version of a file.',\n schema: 'lssm_files',\n map: 'file_version',\n fields: {\n id: field.id({ description: 'Unique version identifier' }),\n fileId: field.foreignKey({ description: 'Parent file' }),\n\n // Version info\n version: field.int({ description: 'Version number' }),\n size: field.int({ description: 'Version size in bytes' }),\n\n // Storage\n storagePath: field.string({ description: 'Path in storage backend' }),\n checksum: field.string({\n isOptional: true,\n description: 'SHA-256 checksum',\n }),\n\n // Metadata\n comment: field.string({ isOptional: true, description: 'Version comment' }),\n changes: field.json({\n isOptional: true,\n description: 'Change description',\n }),\n\n // Creator\n createdBy: field.string({ description: 'User who created version' }),\n\n // Timestamps\n createdAt: field.createdAt(),\n\n // Relations\n file: field.belongsTo('File', ['fileId'], ['id'], { onDelete: 'Cascade' }),\n },\n indexes: [\n index.on(['fileId', 'version']),\n index.unique(['fileId', 'version'], { name: 'file_version_unique' }),\n ],\n});\n\n/**\n * Attachment entity - polymorphic link between files and entities.\n */\nexport const AttachmentEntity = defineEntity({\n name: 'Attachment',\n description: 'Links a file to an entity.',\n schema: 'lssm_files',\n map: 'attachment',\n fields: {\n id: field.id({ description: 'Unique attachment identifier' }),\n fileId: field.foreignKey({ description: 'Attached file' }),\n\n // Target entity (polymorphic)\n entityType: field.string({\n description: 'Target entity type (deal, listing, etc.)',\n }),\n entityId: field.string({ description: 'Target entity ID' }),\n\n // Attachment metadata\n attachmentType: field.string({\n isOptional: true,\n description: 'Type of attachment (document, image, avatar, etc.)',\n }),\n name: field.string({\n isOptional: true,\n description: 'Display name (overrides file name)',\n }),\n description: field.string({\n isOptional: true,\n description: 'Attachment description',\n }),\n\n // Ordering\n order: field.int({ default: 0, description: 'Display order' }),\n\n // Metadata\n metadata: field.json({\n isOptional: true,\n description: 'Attachment-specific metadata',\n }),\n\n // Creator\n createdBy: field.string({ description: 'User who created attachment' }),\n\n // Timestamps\n createdAt: field.createdAt(),\n updatedAt: field.updatedAt(),\n\n // Relations\n file: field.belongsTo('File', ['fileId'], ['id'], { onDelete: 'Cascade' }),\n },\n indexes: [\n index.on(['entityType', 'entityId']),\n index.on(['fileId']),\n index.on(['entityType', 'entityId', 'attachmentType']),\n index.unique(['fileId', 'entityType', 'entityId'], {\n name: 'attachment_unique',\n }),\n ],\n});\n\n/**\n * UploadSession entity - tracks multipart uploads.\n */\nexport const UploadSessionEntity = defineEntity({\n name: 'UploadSession',\n description: 'Tracks a multipart upload session.',\n schema: 'lssm_files',\n map: 'upload_session',\n fields: {\n id: field.id({ description: 'Unique session identifier' }),\n\n // File info\n fileName: field.string({ description: 'Target file name' }),\n mimeType: field.string({ description: 'Expected MIME type' }),\n totalSize: field.int({ description: 'Total file size' }),\n\n // Upload state\n uploadId: field.string({\n isOptional: true,\n description: 'Storage upload ID',\n }),\n uploadedBytes: field.int({\n default: 0,\n description: 'Bytes uploaded so far',\n }),\n uploadedParts: field.json({\n isOptional: true,\n description: 'Completed part info',\n }),\n\n // Status\n status: field.string({\n default: '\"pending\"',\n description: 'Session status',\n }),\n error: field.string({\n isOptional: true,\n description: 'Error message if failed',\n }),\n\n // Result\n fileId: field.string({\n isOptional: true,\n description: 'Resulting file ID',\n }),\n\n // Context\n ownerId: field.string({ description: 'User who initiated upload' }),\n orgId: field.string({\n isOptional: true,\n description: 'Organization scope',\n }),\n\n // Expiry\n expiresAt: field.dateTime({ description: 'Session expiry time' }),\n\n // Timestamps\n createdAt: field.createdAt(),\n updatedAt: field.updatedAt(),\n },\n indexes: [index.on(['status', 'expiresAt']), index.on(['ownerId'])],\n});\n\n/**\n * All file entities for schema composition.\n */\nexport const fileEntities = [\n FileEntity,\n FileVersionEntity,\n AttachmentEntity,\n UploadSessionEntity,\n];\n\n/**\n * Module schema contribution for files.\n */\nexport const filesSchemaContribution: ModuleSchemaContribution = {\n moduleId: '@contractspec/lib.files',\n entities: fileEntities,\n enums: [StorageProviderEnum, FileStatusEnum],\n};\n"],"mappings":";;;;;;AAWA,MAAa,sBAAsB,iBAAiB;CAClD,MAAM;CACN,QAAQ;EAAC;EAAS;EAAM;EAAO;EAAS;EAAa;CACrD,QAAQ;CACR,aAAa;CACd,CAAC;;;;AAKF,MAAa,iBAAiB,iBAAiB;CAC7C,MAAM;CACN,QAAQ;EACN;EACA;EACA;EACA;EACA;EACA;EACD;CACD,QAAQ;CACR,aAAa;CACd,CAAC;;;;AAKF,MAAa,aAAa,aAAa;CACrC,MAAM;CACN,aAAa;CACb,QAAQ;CACR,KAAK;CACL,QAAQ;EACN,IAAI,MAAM,GAAG,EAAE,aAAa,0BAA0B,CAAC;EAGvD,MAAM,MAAM,OAAO,EAAE,aAAa,sBAAsB,CAAC;EACzD,UAAU,MAAM,OAAO,EAAE,aAAa,aAAa,CAAC;EACpD,MAAM,MAAM,IAAI,EAAE,aAAa,sBAAsB,CAAC;EAGtD,iBAAiB,MAAM,KAAK,mBAAmB;GAC7C,SAAS;GACT,aAAa;GACd,CAAC;EACF,aAAa,MAAM,OAAO,EAAE,aAAa,2BAA2B,CAAC;EACrE,YAAY,MAAM,OAAO;GACvB,YAAY;GACZ,aAAa;GACd,CAAC;EAGF,UAAU,MAAM,OAAO;GACrB,YAAY;GACZ,aAAa;GACd,CAAC;EACF,MAAM,MAAM,OAAO;GAAE,YAAY;GAAM,aAAa;GAAgB,CAAC;EAGrE,QAAQ,MAAM,KAAK,cAAc;GAC/B,SAAS;GACT,aAAa;GACd,CAAC;EAGF,UAAU,MAAM,QAAQ;GACtB,SAAS;GACT,aAAa;GACd,CAAC;EACF,WAAW,MAAM,SAAS;GACxB,YAAY;GACZ,aAAa;GACd,CAAC;EAGF,SAAS,MAAM,OAAO,EAAE,aAAa,qBAAqB,CAAC;EAC3D,OAAO,MAAM,OAAO;GAClB,YAA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