@things-factory/media 0.0.0-stage → 10.1.306

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
+ export declare function registerMediaFiles(): void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerMediaFiles = registerMediaFiles;
4
+ /*
5
+ * Who may open a picture's file by its path (ADR-0226 decision 5-1, ADR-0106): whoever may see the picture - the
6
+ * purposes it is used for decide. attachment-base has already checked the file is of the request's domain.
7
+ */
8
+ const attachment_base_1 = require("@things-factory/attachment-base");
9
+ const shell_1 = require("@things-factory/shell");
10
+ const media_item_1 = require("./service/media/media-item");
11
+ const media_service_1 = require("./service/media/media-service");
12
+ function registerMediaFiles() {
13
+ (0, attachment_base_1.registerAttachmentReader)(media_service_1.MEDIA_REF_TYPE, async (attachment, context) => {
14
+ if (!attachment.refBy)
15
+ return false;
16
+ const item = await (0, shell_1.getRepository)(media_item_1.MediaItem).findOne({ where: { id: attachment.refBy } });
17
+ return !!item && (await (0, media_service_1.mayReadMedia)(item, context));
18
+ });
19
+ }
20
+ //# sourceMappingURL=attachment-reader.js.map
@@ -0,0 +1 @@
1
+ export * from './service';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./service"), exports);
5
+ const attachment_reader_1 = require("./attachment-reader");
6
+ (0, attachment_reader_1.registerMediaFiles)();
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ export * from './media/media-item';
2
+ export * from './media/media-use';
3
+ export * from './media/media-purpose';
4
+ export * from './media/media-service';
5
+ export * from './media/media-ai';
6
+ export { MediaFilter, MediaImageModel, MediaImageQuality, MediaItemList, MediaItemPatch, MediaShareFields, MediaShareRoute } from './media/media-resolver';
7
+ export declare const entities: (typeof import("./media/media-item").MediaItem | typeof import("./media/media-use").MediaUse)[];
8
+ export declare const schema: {
9
+ resolverClasses: typeof import("./media/media-resolver").MediaResolver[];
10
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.schema = exports.entities = exports.MediaShareRoute = exports.MediaShareFields = exports.MediaItemPatch = exports.MediaItemList = exports.MediaImageQuality = exports.MediaImageModel = exports.MediaFilter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /* EXPORT ENTITY TYPES */
6
+ tslib_1.__exportStar(require("./media/media-item"), exports);
7
+ tslib_1.__exportStar(require("./media/media-use"), exports);
8
+ tslib_1.__exportStar(require("./media/media-purpose"), exports);
9
+ tslib_1.__exportStar(require("./media/media-service"), exports);
10
+ tslib_1.__exportStar(require("./media/media-ai"), exports);
11
+ var media_resolver_1 = require("./media/media-resolver");
12
+ Object.defineProperty(exports, "MediaFilter", { enumerable: true, get: function () { return media_resolver_1.MediaFilter; } });
13
+ Object.defineProperty(exports, "MediaImageModel", { enumerable: true, get: function () { return media_resolver_1.MediaImageModel; } });
14
+ Object.defineProperty(exports, "MediaImageQuality", { enumerable: true, get: function () { return media_resolver_1.MediaImageQuality; } });
15
+ Object.defineProperty(exports, "MediaItemList", { enumerable: true, get: function () { return media_resolver_1.MediaItemList; } });
16
+ Object.defineProperty(exports, "MediaItemPatch", { enumerable: true, get: function () { return media_resolver_1.MediaItemPatch; } });
17
+ Object.defineProperty(exports, "MediaShareFields", { enumerable: true, get: function () { return media_resolver_1.MediaShareFields; } });
18
+ Object.defineProperty(exports, "MediaShareRoute", { enumerable: true, get: function () { return media_resolver_1.MediaShareRoute; } });
19
+ /* IMPORT ENTITIES AND RESOLVERS */
20
+ const media_1 = require("./media");
21
+ exports.entities = [
22
+ /* ENTITIES */
23
+ ...media_1.entities
24
+ ];
25
+ exports.schema = {
26
+ resolverClasses: [
27
+ /* RESOLVER CLASSES */
28
+ ...media_1.resolvers
29
+ ]
30
+ };
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ import { MediaItem } from './media-item';
2
+ import { MediaResolver } from './media-resolver';
3
+ import { MediaUse } from './media-use';
4
+ export declare const entities: (typeof MediaItem | typeof MediaUse)[];
5
+ export declare const resolvers: (typeof MediaResolver)[];
6
+ export declare const subscribers: any[];
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.subscribers = exports.resolvers = exports.entities = void 0;
4
+ const media_item_1 = require("./media-item");
5
+ const media_resolver_1 = require("./media-resolver");
6
+ const media_use_1 = require("./media-use");
7
+ exports.entities = [media_item_1.MediaItem, media_use_1.MediaUse];
8
+ exports.resolvers = [media_resolver_1.MediaResolver];
9
+ exports.subscribers = [];
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,38 @@
1
+ import { type AiAgentDirectory, type ImageQuality } from '@things-factory/ai-client-base';
2
+ import { Refusal } from '@things-factory/shell';
3
+ import { MediaItem } from './media-item';
4
+ export declare const IMAGE_SIZES: string[];
5
+ export interface ImageAgent {
6
+ agentId: string;
7
+ agentName: string;
8
+ provider: string;
9
+ model: string;
10
+ isDefault: boolean;
11
+ qualities: {
12
+ quality: ImageQuality;
13
+ price?: number;
14
+ }[];
15
+ }
16
+ /**
17
+ * The agents of a directory that make pictures, each with its image model and what a picture costs at each quality.
18
+ * The default is the domain's default agent when it makes pictures, else the first that does (decision 8-1).
19
+ */
20
+ export declare function imageAgentsOf(directory: Pick<AiAgentDirectory, 'entries' | 'defaultAgentId'>): ImageAgent[];
21
+ /** The image agents the request may make pictures with, for a purpose that allows AI pictures - none otherwise. */
22
+ export declare function imageAgentsFor(purposeName: string, context: any): Promise<ImageAgent[]>;
23
+ export interface AiPictureAsk {
24
+ purpose: string;
25
+ prompt: string;
26
+ agentId?: string | null;
27
+ quality?: string | null;
28
+ size?: string | null;
29
+ targetType?: string | null;
30
+ targetId?: string | null;
31
+ }
32
+ /** Why an ask may not make a picture, before any model is called - or null. */
33
+ export declare function aiAskRefusal(ask: AiPictureAsk): Refusal | null;
34
+ /**
35
+ * Makes a picture by AI and adds it under the purpose: the purpose must allow AI pictures and let the request add, its
36
+ * prompt check must let the words by, and the agent must make pictures. Put on the record named, when one is.
37
+ */
38
+ export declare function createMediaByAi(ask: AiPictureAsk, context: any): Promise<MediaItem>;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IMAGE_SIZES = void 0;
4
+ exports.imageAgentsOf = imageAgentsOf;
5
+ exports.imageAgentsFor = imageAgentsFor;
6
+ exports.aiAskRefusal = aiAskRefusal;
7
+ exports.createMediaByAi = createMediaByAi;
8
+ const stream_1 = require("stream");
9
+ const ai_client_base_1 = require("@things-factory/ai-client-base");
10
+ const shell_1 = require("@things-factory/shell");
11
+ const media_item_1 = require("./media-item");
12
+ const media_purpose_1 = require("./media-purpose");
13
+ const media_service_1 = require("./media-service");
14
+ /*
15
+ * AI 생성 (ADR-0226 decisions 8, 8-1) - a picture made from words by an image model of the domain's AI agents, added
16
+ * to the library under a purpose that allows it. The models are the agents' (an image model field on each agent,
17
+ * its provider's default when empty); the person picks one when making. A made picture starts held INTERNAL and
18
+ * unconfirmed, says it was made by AI, and records the prompt, agent, model, quality and its price.
19
+ */
20
+ exports.IMAGE_SIZES = ['1024x1024', '1024x1536', '1536x1024'];
21
+ const QUALITIES = ['low', 'medium', 'high'];
22
+ const MAX_PROMPT = 4000;
23
+ /**
24
+ * The agents of a directory that make pictures, each with its image model and what a picture costs at each quality.
25
+ * The default is the domain's default agent when it makes pictures, else the first that does (decision 8-1).
26
+ */
27
+ function imageAgentsOf(directory) {
28
+ const agents = directory.entries
29
+ .filter(one => one.usable && (0, ai_client_base_1.imageModelOf)(one.spec))
30
+ .map(one => {
31
+ const model = (0, ai_client_base_1.imageModelOf)(one.spec);
32
+ return {
33
+ agentId: one.spec.id,
34
+ agentName: one.spec.name,
35
+ provider: one.spec.provider,
36
+ model,
37
+ isDefault: false,
38
+ qualities: (0, ai_client_base_1.imageQualitiesOf)(model).map(quality => ({ quality, price: (0, ai_client_base_1.imagePriceOf)(model, quality) }))
39
+ };
40
+ });
41
+ const preferred = agents.find(one => one.agentId === directory.defaultAgentId) ?? agents[0];
42
+ if (preferred)
43
+ preferred.isDefault = true;
44
+ return agents;
45
+ }
46
+ /** The image agents the request may make pictures with, for a purpose that allows AI pictures - none otherwise. */
47
+ async function imageAgentsFor(purposeName, context) {
48
+ const purpose = (0, media_purpose_1.purposeOrRefuse)(purposeName);
49
+ if (!purpose.aiCreation || !purpose.mayAdd || !(await purpose.mayAdd(context)))
50
+ return [];
51
+ return imageAgentsOf(await (0, ai_client_base_1.readAiAgentDirectory)(context.state.domain));
52
+ }
53
+ /** Why an ask may not make a picture, before any model is called - or null. */
54
+ function aiAskRefusal(ask) {
55
+ const prompt = (ask.prompt ?? '').trim();
56
+ if (!prompt)
57
+ return new shell_1.Refusal('media-ai-prompt-required', {}, 'say what the picture should show');
58
+ if (prompt.length > MAX_PROMPT)
59
+ return new shell_1.Refusal('media-ai-prompt-too-long', { max: MAX_PROMPT }, `a prompt holds at most ${MAX_PROMPT} characters`);
60
+ if (ask.quality && !QUALITIES.includes(ask.quality))
61
+ return new shell_1.Refusal('media-ai-quality-unknown', { quality: ask.quality }, 'the quality is low, medium or high');
62
+ if (ask.size && !exports.IMAGE_SIZES.includes(ask.size))
63
+ return new shell_1.Refusal('media-ai-size-unknown', { size: ask.size }, `the size is one of ${exports.IMAGE_SIZES.join(', ')}`);
64
+ if (!!ask.targetType !== !!ask.targetId)
65
+ return new shell_1.Refusal('media-target-incomplete', {}, 'a record is named by its kind and its id');
66
+ return null;
67
+ }
68
+ /**
69
+ * Makes a picture by AI and adds it under the purpose: the purpose must allow AI pictures and let the request add, its
70
+ * prompt check must let the words by, and the agent must make pictures. Put on the record named, when one is.
71
+ */
72
+ async function createMediaByAi(ask, context) {
73
+ const { domain, user } = context.state;
74
+ const purpose = (0, media_purpose_1.purposeOrRefuse)(ask.purpose);
75
+ if (!purpose.aiCreation)
76
+ throw new shell_1.Refusal('media-ai-not-allowed', { purpose: ask.purpose }, 'pictures of this purpose are not made by AI');
77
+ if (!purpose.mayAdd || !(await purpose.mayAdd(context)))
78
+ throw new shell_1.Refusal('media-add-denied', {}, 'pictures are not added here');
79
+ const refusal = aiAskRefusal(ask);
80
+ if (refusal)
81
+ throw refusal;
82
+ const prompt = ask.prompt.trim();
83
+ if (ask.targetType && !(await purpose.mayRead({ targetType: ask.targetType, targetId: ask.targetId }, context)))
84
+ throw new shell_1.Refusal('media-read-denied', {}, 'the record is not one the request may see');
85
+ const checked = purpose.checkPrompt ? await purpose.checkPrompt(prompt, context) : null;
86
+ if (checked)
87
+ throw checked;
88
+ const agentId = ask.agentId || (await imageAgentsFor(ask.purpose, context)).find(one => one.isDefault)?.agentId;
89
+ if (!agentId)
90
+ throw new shell_1.Refusal('media-ai-no-model', {}, 'no AI agent here makes pictures');
91
+ const client = await (0, ai_client_base_1.aiClientFor)({ domain, user, agentId });
92
+ if (!client.generateImage)
93
+ throw new shell_1.Refusal('media-ai-no-model', {}, 'the AI agent picked does not make pictures');
94
+ const quality = ask.quality || 'medium';
95
+ const image = await client.generateImage(prompt, { quality, size: ask.size || exports.IMAGE_SIZES[0] });
96
+ const extension = image.mimetype === 'image/jpeg' ? 'jpg' : image.mimetype === 'image/webp' ? 'webp' : 'png';
97
+ const stamp = new Date().toISOString().replace(/[-:]/g, '').slice(0, 15);
98
+ const upload = { filename: `ai-${stamp}.${extension}`, mimetype: image.mimetype, encoding: '7bit', createReadStream: () => stream_1.Readable.from(image.data) };
99
+ const item = await (0, media_service_1.addMedia)({
100
+ file: Promise.resolve(upload),
101
+ home: ask.purpose,
102
+ title: prompt.length > 60 ? `${prompt.slice(0, 59)}…` : prompt,
103
+ kind: media_item_1.MediaKind.ILLUSTRATION,
104
+ origin: media_item_1.MediaOrigin.AI,
105
+ generation: { prompt, agentId: client.agent.id, model: image.model, quality, cost: (0, ai_client_base_1.imagePriceOf)(image.model, quality) },
106
+ tags: ['AI']
107
+ }, context);
108
+ if (ask.targetType)
109
+ await (0, media_service_1.useMedia)({ itemId: item.id, purpose: ask.purpose, targetType: ask.targetType, targetId: ask.targetId }, context);
110
+ return item;
111
+ }
112
+ //# sourceMappingURL=media-ai.js.map
@@ -0,0 +1,69 @@
1
+ import { Domain } from '@things-factory/shell';
2
+ import { User } from '@things-factory/auth-base';
3
+ import { Attachment } from '@things-factory/attachment-base';
4
+ /** How far a picture may be shown - the content ledger's grades (ADR-0223 decision 4). Unconfirmed, it is held INTERNAL. */
5
+ export declare enum MediaExposure {
6
+ INTERNAL = "INTERNAL",
7
+ CUSTOMER = "CUSTOMER",
8
+ PUBLIC = "PUBLIC"
9
+ }
10
+ /** What kind of picture it is. */
11
+ export declare enum MediaKind {
12
+ PHOTO = "PHOTO",
13
+ ILLUSTRATION = "ILLUSTRATION",
14
+ SCREENSHOT = "SCREENSHOT",
15
+ DIAGRAM = "DIAGRAM",
16
+ VIDEO = "VIDEO"
17
+ }
18
+ /** Where a picture came from - what rights it is held under. */
19
+ export declare enum MediaOrigin {
20
+ OWN = "OWN",
21
+ LICENSED = "LICENSED",
22
+ PARTNER = "PARTNER",
23
+ AI = "AI"
24
+ }
25
+ /** Whether people are in it, and whether they agreed to be shown. */
26
+ export declare enum MediaPeople {
27
+ NONE = "NONE",
28
+ CONSENTED = "CONSENTED",
29
+ NOT_ASKED = "NOT_ASKED"
30
+ }
31
+ /**
32
+ * 미디어 - one picture of the library (ADR-0226 decision 2): one attachment (its file, name, description, tags and
33
+ * thumbnail stay there) and what the attachment does not say - how far it may be shown, its rights, the people in it,
34
+ * how it was made, and the purpose that manages it. Where it is used are its uses (media-use.ts).
35
+ */
36
+ export declare class MediaItem {
37
+ readonly id: string;
38
+ domain?: Domain;
39
+ domainId?: string;
40
+ attachment?: Attachment;
41
+ attachmentId?: string;
42
+ title?: string;
43
+ kind: MediaKind;
44
+ takenAt?: Date;
45
+ place?: string;
46
+ exposure: MediaExposure;
47
+ exposureConfirmed: boolean;
48
+ origin: MediaOrigin;
49
+ rightsNote?: string;
50
+ rightsUntil?: string;
51
+ people: MediaPeople;
52
+ generation?: {
53
+ prompt: string;
54
+ agentId?: string;
55
+ model: string;
56
+ quality?: string;
57
+ cost?: number;
58
+ };
59
+ home: string;
60
+ owner?: User;
61
+ ownerId?: string;
62
+ createdAt?: Date;
63
+ updatedAt?: Date;
64
+ deletedAt?: Date;
65
+ creator?: User;
66
+ creatorId?: string;
67
+ updater?: User;
68
+ updaterId?: string;
69
+ }
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MediaItem = exports.MediaPeople = exports.MediaOrigin = exports.MediaKind = exports.MediaExposure = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const typeorm_1 = require("typeorm");
6
+ const type_graphql_1 = require("type-graphql");
7
+ const shell_1 = require("@things-factory/shell");
8
+ const auth_base_1 = require("@things-factory/auth-base");
9
+ const attachment_base_1 = require("@things-factory/attachment-base");
10
+ /** How far a picture may be shown - the content ledger's grades (ADR-0223 decision 4). Unconfirmed, it is held INTERNAL. */
11
+ var MediaExposure;
12
+ (function (MediaExposure) {
13
+ MediaExposure["INTERNAL"] = "INTERNAL";
14
+ MediaExposure["CUSTOMER"] = "CUSTOMER";
15
+ MediaExposure["PUBLIC"] = "PUBLIC";
16
+ })(MediaExposure || (exports.MediaExposure = MediaExposure = {}));
17
+ /** What kind of picture it is. */
18
+ var MediaKind;
19
+ (function (MediaKind) {
20
+ MediaKind["PHOTO"] = "PHOTO";
21
+ MediaKind["ILLUSTRATION"] = "ILLUSTRATION";
22
+ MediaKind["SCREENSHOT"] = "SCREENSHOT";
23
+ MediaKind["DIAGRAM"] = "DIAGRAM";
24
+ MediaKind["VIDEO"] = "VIDEO";
25
+ })(MediaKind || (exports.MediaKind = MediaKind = {}));
26
+ /** Where a picture came from - what rights it is held under. */
27
+ var MediaOrigin;
28
+ (function (MediaOrigin) {
29
+ MediaOrigin["OWN"] = "OWN";
30
+ MediaOrigin["LICENSED"] = "LICENSED";
31
+ MediaOrigin["PARTNER"] = "PARTNER";
32
+ MediaOrigin["AI"] = "AI";
33
+ })(MediaOrigin || (exports.MediaOrigin = MediaOrigin = {}));
34
+ /** Whether people are in it, and whether they agreed to be shown. */
35
+ var MediaPeople;
36
+ (function (MediaPeople) {
37
+ MediaPeople["NONE"] = "NONE";
38
+ MediaPeople["CONSENTED"] = "CONSENTED";
39
+ MediaPeople["NOT_ASKED"] = "NOT_ASKED";
40
+ })(MediaPeople || (exports.MediaPeople = MediaPeople = {}));
41
+ for (const [one, name, description] of [
42
+ [MediaExposure, 'MediaExposure', 'How far a picture may be shown - internal, customer or public'],
43
+ [MediaKind, 'MediaKind', 'What kind of picture a media item is'],
44
+ [MediaOrigin, 'MediaOrigin', 'Where a picture came from - own, licensed, a partner or made by AI'],
45
+ [MediaPeople, 'MediaPeople', 'Whether people are in a picture and whether they agreed to be shown']
46
+ ])
47
+ (0, type_graphql_1.registerEnumType)(one, { name, description });
48
+ /**
49
+ * 미디어 - one picture of the library (ADR-0226 decision 2): one attachment (its file, name, description, tags and
50
+ * thumbnail stay there) and what the attachment does not say - how far it may be shown, its rights, the people in it,
51
+ * how it was made, and the purpose that manages it. Where it is used are its uses (media-use.ts).
52
+ */
53
+ let MediaItem = class MediaItem {
54
+ };
55
+ exports.MediaItem = MediaItem;
56
+ tslib_1.__decorate([
57
+ (0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
58
+ (0, type_graphql_1.Field)(type => type_graphql_1.ID),
59
+ tslib_1.__metadata("design:type", String)
60
+ ], MediaItem.prototype, "id", void 0);
61
+ tslib_1.__decorate([
62
+ (0, typeorm_1.ManyToOne)(type => shell_1.Domain),
63
+ (0, type_graphql_1.Field)(type => shell_1.Domain, { nullable: true }),
64
+ tslib_1.__metadata("design:type", shell_1.Domain)
65
+ ], MediaItem.prototype, "domain", void 0);
66
+ tslib_1.__decorate([
67
+ (0, typeorm_1.RelationId)((row) => row.domain),
68
+ tslib_1.__metadata("design:type", String)
69
+ ], MediaItem.prototype, "domainId", void 0);
70
+ tslib_1.__decorate([
71
+ (0, typeorm_1.ManyToOne)(type => attachment_base_1.Attachment, { nullable: true }),
72
+ tslib_1.__metadata("design:type", attachment_base_1.Attachment)
73
+ ], MediaItem.prototype, "attachment", void 0);
74
+ tslib_1.__decorate([
75
+ (0, typeorm_1.RelationId)((row) => row.attachment),
76
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Id of the attachment that holds the file' }),
77
+ tslib_1.__metadata("design:type", String)
78
+ ], MediaItem.prototype, "attachmentId", void 0);
79
+ tslib_1.__decorate([
80
+ (0, typeorm_1.Column)({ nullable: true }),
81
+ (0, type_graphql_1.Field)({ nullable: true, description: 'What the picture is called' }),
82
+ tslib_1.__metadata("design:type", String)
83
+ ], MediaItem.prototype, "title", void 0);
84
+ tslib_1.__decorate([
85
+ (0, typeorm_1.Column)({ default: MediaKind.PHOTO }),
86
+ (0, type_graphql_1.Field)(type => MediaKind, { description: 'What kind of picture it is' }),
87
+ tslib_1.__metadata("design:type", String)
88
+ ], MediaItem.prototype, "kind", void 0);
89
+ tslib_1.__decorate([
90
+ (0, typeorm_1.Column)({ nullable: true }),
91
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When it was taken' }),
92
+ tslib_1.__metadata("design:type", Date)
93
+ ], MediaItem.prototype, "takenAt", void 0);
94
+ tslib_1.__decorate([
95
+ (0, typeorm_1.Column)({ nullable: true }),
96
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Where it was taken' }),
97
+ tslib_1.__metadata("design:type", String)
98
+ ], MediaItem.prototype, "place", void 0);
99
+ tslib_1.__decorate([
100
+ (0, typeorm_1.Column)({ default: MediaExposure.INTERNAL }),
101
+ (0, type_graphql_1.Field)(type => MediaExposure, { description: 'How far it may be shown' }),
102
+ tslib_1.__metadata("design:type", String)
103
+ ], MediaItem.prototype, "exposure", void 0);
104
+ tslib_1.__decorate([
105
+ (0, typeorm_1.Column)({ default: false }),
106
+ (0, type_graphql_1.Field)({ description: 'Whether a person confirmed how far it may be shown - unconfirmed, it is held INTERNAL' }),
107
+ tslib_1.__metadata("design:type", Boolean)
108
+ ], MediaItem.prototype, "exposureConfirmed", void 0);
109
+ tslib_1.__decorate([
110
+ (0, typeorm_1.Column)({ default: MediaOrigin.OWN }),
111
+ (0, type_graphql_1.Field)(type => MediaOrigin, { description: 'Where it came from' }),
112
+ tslib_1.__metadata("design:type", String)
113
+ ], MediaItem.prototype, "origin", void 0);
114
+ tslib_1.__decorate([
115
+ (0, typeorm_1.Column)({ type: 'text', nullable: true }),
116
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The terms it is held under' }),
117
+ tslib_1.__metadata("design:type", String)
118
+ ], MediaItem.prototype, "rightsNote", void 0);
119
+ tslib_1.__decorate([
120
+ (0, typeorm_1.Column)({ nullable: true }),
121
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The last day it may be used, YYYY-MM-DD' }),
122
+ tslib_1.__metadata("design:type", String)
123
+ ], MediaItem.prototype, "rightsUntil", void 0);
124
+ tslib_1.__decorate([
125
+ (0, typeorm_1.Column)({ default: MediaPeople.NOT_ASKED }),
126
+ (0, type_graphql_1.Field)(type => MediaPeople, { description: 'Whether people are in it and agreed to be shown' }),
127
+ tslib_1.__metadata("design:type", String)
128
+ ], MediaItem.prototype, "people", void 0);
129
+ tslib_1.__decorate([
130
+ (0, typeorm_1.Column)('simple-json', { nullable: true }),
131
+ (0, type_graphql_1.Field)(type => shell_1.ScalarObject, { nullable: true, description: 'How it was made when made by AI - the prompt, agent, model, quality and cost' }),
132
+ tslib_1.__metadata("design:type", Object)
133
+ ], MediaItem.prototype, "generation", void 0);
134
+ tslib_1.__decorate([
135
+ (0, typeorm_1.Column)(),
136
+ (0, type_graphql_1.Field)({ description: 'The purpose that manages it - its writers change its facts and delete it' }),
137
+ tslib_1.__metadata("design:type", String)
138
+ ], MediaItem.prototype, "home", void 0);
139
+ tslib_1.__decorate([
140
+ (0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
141
+ (0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true, description: "The person it belongs to, when it is a person's own" }),
142
+ tslib_1.__metadata("design:type", auth_base_1.User)
143
+ ], MediaItem.prototype, "owner", void 0);
144
+ tslib_1.__decorate([
145
+ (0, typeorm_1.RelationId)((row) => row.owner),
146
+ tslib_1.__metadata("design:type", String)
147
+ ], MediaItem.prototype, "ownerId", void 0);
148
+ tslib_1.__decorate([
149
+ (0, typeorm_1.CreateDateColumn)(),
150
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When it was added' }),
151
+ tslib_1.__metadata("design:type", Date)
152
+ ], MediaItem.prototype, "createdAt", void 0);
153
+ tslib_1.__decorate([
154
+ (0, typeorm_1.UpdateDateColumn)(),
155
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When it was last changed' }),
156
+ tslib_1.__metadata("design:type", Date)
157
+ ], MediaItem.prototype, "updatedAt", void 0);
158
+ tslib_1.__decorate([
159
+ (0, typeorm_1.DeleteDateColumn)(),
160
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When it was removed from the library' }),
161
+ tslib_1.__metadata("design:type", Date)
162
+ ], MediaItem.prototype, "deletedAt", void 0);
163
+ tslib_1.__decorate([
164
+ (0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
165
+ (0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true }),
166
+ tslib_1.__metadata("design:type", auth_base_1.User)
167
+ ], MediaItem.prototype, "creator", void 0);
168
+ tslib_1.__decorate([
169
+ (0, typeorm_1.RelationId)((row) => row.creator),
170
+ tslib_1.__metadata("design:type", String)
171
+ ], MediaItem.prototype, "creatorId", void 0);
172
+ tslib_1.__decorate([
173
+ (0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
174
+ (0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true }),
175
+ tslib_1.__metadata("design:type", auth_base_1.User)
176
+ ], MediaItem.prototype, "updater", void 0);
177
+ tslib_1.__decorate([
178
+ (0, typeorm_1.RelationId)((row) => row.updater),
179
+ tslib_1.__metadata("design:type", String)
180
+ ], MediaItem.prototype, "updaterId", void 0);
181
+ exports.MediaItem = MediaItem = tslib_1.__decorate([
182
+ (0, typeorm_1.Entity)({ name: 'media_items' }),
183
+ (0, typeorm_1.Index)('ix_media_item_0', (row) => [row.domain, row.home]),
184
+ (0, typeorm_1.Index)('ix_media_item_1', (row) => [row.domain, row.attachment]),
185
+ (0, type_graphql_1.ObjectType)({ description: 'Entity for MediaItem - one picture of the media library' })
186
+ ], MediaItem);
187
+ //# sourceMappingURL=media-item.js.map
@@ -0,0 +1,87 @@
1
+ import { Refusal } from '@things-factory/shell';
2
+ export interface MediaShareRoute {
3
+ /** The purpose a picture may be shared to. */
4
+ purpose: string;
5
+ /** The receiving purpose takes it in first ("받은 사진") and manages it once it accepts. */
6
+ accept?: boolean;
7
+ /** Only the person the picture belongs to may share it. */
8
+ ownerOnly?: boolean;
9
+ }
10
+ /** What a person types when sharing pictures to a purpose that makes its own record of them (a gallery post). */
11
+ export interface MediaShareInput {
12
+ caption?: string | null;
13
+ tags?: string[] | null;
14
+ eventId?: string | null;
15
+ }
16
+ export interface MediaPurpose {
17
+ name: string;
18
+ /** The i18n key of the purpose's name - what a share button and an inbox say ("마케팅", "갤러리"). */
19
+ label?: string;
20
+ /** Whether the request may see the pictures used on this record of the purpose. */
21
+ mayRead: (target: {
22
+ targetType: string;
23
+ targetId: string;
24
+ }, context: any) => Promise<boolean> | boolean;
25
+ /** Whether the request manages a picture this purpose is home of - changes its facts and deletes it. */
26
+ mayManage: (item: {
27
+ ownerId?: string | null;
28
+ creatorId?: string | null;
29
+ }, context: any) => Promise<boolean> | boolean;
30
+ /** 'by-target': a picture used on a CUSTOMER or PUBLIC record needs its people's consent and live rights. */
31
+ peopleConsent: 'not-required' | 'by-target';
32
+ /**
33
+ * Whether a picture this purpose manages stays when its last use is taken off - a library of pictures (marketing) keeps
34
+ * it; a purpose whose pictures live on its records (the gallery's posts) lets it go with its file.
35
+ */
36
+ keepUnused?: boolean;
37
+ /** Whether pictures of this purpose may be made by AI (decision 8). */
38
+ aiCreation?: boolean;
39
+ shareTo?: MediaShareRoute[];
40
+ /** Whether the request may add pictures straight under this purpose (the upload door). Absent, nobody may - the purpose adds through its own doors. */
41
+ mayAdd?: (context: any) => Promise<boolean> | boolean;
42
+ /**
43
+ * Takes in pictures shared to it on a route without `accept` - the receiving purpose makes its own record of them
44
+ * (the gallery makes a post). Called in the sharing request's transaction.
45
+ */
46
+ receive?: (itemIds: string[], input: MediaShareInput, context: any) => Promise<void>;
47
+ /** Refuses a prompt before a picture is made by AI for this purpose (decision 8) - null lets it by. */
48
+ checkPrompt?: (prompt: string, context: any) => Promise<Refusal | null> | Refusal | null;
49
+ }
50
+ /** The inbox a route with `accept` puts a shared picture in - one per domain and purpose ("받은 사진"). */
51
+ export declare const MEDIA_INBOX = "MediaInbox";
52
+ /** A module declares one purpose - at import time. The same name again replaces it (a watch rebuild imports twice). */
53
+ export declare function registerMediaPurpose(purpose: MediaPurpose): void;
54
+ export declare function mediaPurposeOf(name: string): MediaPurpose | undefined;
55
+ export declare function declaredMediaPurposes(): MediaPurpose[];
56
+ /** The purpose, or a refusal - a use names only a declared purpose. */
57
+ export declare function purposeOrRefuse(name: string): MediaPurpose;
58
+ /** How far an item may be shown now - an unconfirmed exposure is held INTERNAL (decision 2). */
59
+ export declare function effectiveExposure(item: {
60
+ exposure: string;
61
+ exposureConfirmed?: boolean | null;
62
+ }): string;
63
+ /**
64
+ * Decision 4 - whether a picture may be used on a record shown this far: never on a record shown further than the
65
+ * picture may be; and, where the purpose asks it, an outward record takes no picture whose people were not asked or
66
+ * whose rights have ended.
67
+ */
68
+ export declare function useRefusal(item: {
69
+ exposure: string;
70
+ exposureConfirmed?: boolean | null;
71
+ people: string;
72
+ rightsUntil?: string | null;
73
+ }, purpose: Pick<MediaPurpose, 'peopleConsent'>, targetExposure: string, today: string): Refusal | null;
74
+ /**
75
+ * Decision 4 again, when a picture's facts change: it may not come to be shown less far than a record it is used on
76
+ * already is - take it off that record first.
77
+ */
78
+ export declare function narrowingRefusal(item: {
79
+ exposure: string;
80
+ exposureConfirmed?: boolean | null;
81
+ }, uses: {
82
+ targetExposure: string;
83
+ }[]): Refusal | null;
84
+ /** Decision 5-2 - whether a picture of `from` may be shared to `to`, and by the request's person. */
85
+ export declare function shareRefusal(from: Pick<MediaPurpose, 'name' | 'shareTo'>, to: string, item: {
86
+ ownerId?: string | null;
87
+ }, userId: string): Refusal | null;