@party-stack/foundry-ontology 0.17.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adapter/convertLoadSubsetOptions.d.ts +2 -0
- package/lib/adapter/convertLoadSubsetOptions.d.ts.map +1 -1
- package/lib/adapter/convertLoadSubsetOptions.js +158 -191
- package/lib/adapter/convertLoadSubsetOptions.js.map +1 -1
- package/lib/adapter/createFoundryOntologyBackendAdapter.d.ts +17 -15
- package/lib/adapter/createFoundryOntologyBackendAdapter.d.ts.map +1 -1
- package/lib/adapter/createFoundryOntologyBackendAdapter.js +288 -400
- package/lib/adapter/createFoundryOntologyBackendAdapter.js.map +1 -1
- package/lib/adapter/foundryActionValidation.d.ts +17 -15
- package/lib/adapter/foundryActionValidation.d.ts.map +1 -1
- package/lib/adapter/foundryActionValidation.js +206 -305
- package/lib/adapter/foundryActionValidation.js.map +1 -1
- package/lib/adapter/foundryCodec.d.ts +10 -9
- package/lib/adapter/foundryCodec.d.ts.map +1 -1
- package/lib/adapter/foundryCodec.js +180 -287
- package/lib/adapter/foundryCodec.js.map +1 -1
- package/lib/adapter/foundryMediaId.d.ts +6 -4
- package/lib/adapter/foundryMediaId.d.ts.map +1 -1
- package/lib/adapter/foundryMediaId.js +31 -32
- package/lib/adapter/foundryMediaId.js.map +1 -1
- package/lib/adapter/index.d.ts +4 -4
- package/lib/adapter/index.js +4 -4
- package/lib/adapter/objectCollectionOptions.d.ts +17 -18
- package/lib/adapter/objectCollectionOptions.d.ts.map +1 -1
- package/lib/adapter/objectCollectionOptions.js +417 -538
- package/lib/adapter/objectCollectionOptions.js.map +1 -1
- package/lib/config/applyAttachmentConstraintOverrides.d.ts +6 -4
- package/lib/config/applyAttachmentConstraintOverrides.d.ts.map +1 -1
- package/lib/config/applyAttachmentConstraintOverrides.js +45 -49
- package/lib/config/applyAttachmentConstraintOverrides.js.map +1 -1
- package/lib/config/index.d.ts +17 -15
- package/lib/config/index.d.ts.map +1 -1
- package/lib/config/index.js +56 -81
- package/lib/config/index.js.map +1 -1
- package/lib/connection.d.ts +28 -26
- package/lib/connection.d.ts.map +1 -1
- package/lib/connection.js +183 -215
- package/lib/connection.js.map +1 -1
- package/lib/index.d.ts +9 -5
- package/lib/index.js +9 -5
- package/lib/installation/createFoundryBackendInstallation.d.ts +21 -20
- package/lib/installation/createFoundryBackendInstallation.d.ts.map +1 -1
- package/lib/installation/createFoundryBackendInstallation.js +52 -62
- package/lib/installation/createFoundryBackendInstallation.js.map +1 -1
- package/lib/installation/index.d.ts +2 -2
- package/lib/installation/index.js +2 -2
- package/lib/meta/actionTypeCollectionOptions.d.ts +8 -6
- package/lib/meta/actionTypeCollectionOptions.d.ts.map +1 -1
- package/lib/meta/actionTypeCollectionOptions.js +49 -49
- package/lib/meta/actionTypeCollectionOptions.js.map +1 -1
- package/lib/meta/convertActionTypeLoadSubsetOptions.d.ts +3 -1
- package/lib/meta/convertActionTypeLoadSubsetOptions.d.ts.map +1 -1
- package/lib/meta/convertActionTypeLoadSubsetOptions.js +69 -75
- package/lib/meta/convertActionTypeLoadSubsetOptions.js.map +1 -1
- package/lib/meta/convertMetaActionType.d.ts +7 -5
- package/lib/meta/convertMetaActionType.d.ts.map +1 -1
- package/lib/meta/convertMetaActionType.js +458 -581
- package/lib/meta/convertMetaActionType.js.map +1 -1
- package/lib/meta/convertMetaLinkType.d.ts +4 -2
- package/lib/meta/convertMetaLinkType.d.ts.map +1 -1
- package/lib/meta/convertMetaLinkType.js +37 -43
- package/lib/meta/convertMetaLinkType.js.map +1 -1
- package/lib/meta/convertMetaObjectType.d.ts +4 -2
- package/lib/meta/convertMetaObjectType.d.ts.map +1 -1
- package/lib/meta/convertMetaObjectType.js +34 -35
- package/lib/meta/convertMetaObjectType.js.map +1 -1
- package/lib/meta/convertMetaQueryFunctionType.d.ts +4 -2
- package/lib/meta/convertMetaQueryFunctionType.d.ts.map +1 -1
- package/lib/meta/convertMetaQueryFunctionType.js +113 -94
- package/lib/meta/convertMetaQueryFunctionType.js.map +1 -1
- package/lib/meta/convertMetaTypeDef.d.ts +4 -2
- package/lib/meta/convertMetaTypeDef.d.ts.map +1 -1
- package/lib/meta/convertMetaTypeDef.js +178 -176
- package/lib/meta/convertMetaTypeDef.js.map +1 -1
- package/lib/meta/convertMetaValueType.d.ts +4 -2
- package/lib/meta/convertMetaValueType.d.ts.map +1 -1
- package/lib/meta/convertMetaValueType.js +11 -7
- package/lib/meta/convertMetaValueType.js.map +1 -1
- package/lib/meta/convertOmsActionParameterMetadata.d.ts +4 -2
- package/lib/meta/convertOmsActionParameterMetadata.d.ts.map +1 -1
- package/lib/meta/convertOmsActionParameterMetadata.js +107 -163
- package/lib/meta/convertOmsActionParameterMetadata.js.map +1 -1
- package/lib/meta/createFoundryMetaOntologyBackendAdapter.d.ts +7 -5
- package/lib/meta/createFoundryMetaOntologyBackendAdapter.d.ts.map +1 -1
- package/lib/meta/createFoundryMetaOntologyBackendAdapter.js +39 -41
- package/lib/meta/createFoundryMetaOntologyBackendAdapter.js.map +1 -1
- package/lib/meta/entityCollectionOptions.d.ts +12 -11
- package/lib/meta/entityCollectionOptions.d.ts.map +1 -1
- package/lib/meta/entityCollectionOptions.js +59 -62
- package/lib/meta/entityCollectionOptions.js.map +1 -1
- package/lib/meta/foundryAttachmentMetadata.d.ts +2 -0
- package/lib/meta/foundryAttachmentMetadata.d.ts.map +1 -1
- package/lib/meta/foundryAttachmentMetadata.js +13 -14
- package/lib/meta/foundryAttachmentMetadata.js.map +1 -1
- package/lib/meta/index.d.ts +5 -5
- package/lib/meta/index.js +5 -5
- package/lib/meta/loadActionTypeOmsMetadata.d.ts +5 -4
- package/lib/meta/loadActionTypeOmsMetadata.d.ts.map +1 -1
- package/lib/meta/loadActionTypeOmsMetadata.js +102 -139
- package/lib/meta/loadActionTypeOmsMetadata.js.map +1 -1
- package/lib/meta/queryFunctionTypeCollectionOptions.d.ts +7 -5
- package/lib/meta/queryFunctionTypeCollectionOptions.d.ts.map +1 -1
- package/lib/meta/queryFunctionTypeCollectionOptions.js +47 -49
- package/lib/meta/queryFunctionTypeCollectionOptions.js.map +1 -1
- package/lib/stagedWrites.d.ts +26 -24
- package/lib/stagedWrites.d.ts.map +1 -1
- package/lib/stagedWrites.js +55 -66
- package/lib/stagedWrites.js.map +1 -1
- package/lib/users/createFoundryAdminOntologyRoute.d.ts +47 -17366
- package/lib/users/createFoundryAdminOntologyRoute.d.ts.map +1 -1
- package/lib/users/createFoundryAdminOntologyRoute.js +29 -37
- package/lib/users/createFoundryAdminOntologyRoute.js.map +1 -1
- package/lib/users/createFoundryUsersIntegration.d.ts +6 -4
- package/lib/users/createFoundryUsersIntegration.d.ts.map +1 -1
- package/lib/users/createFoundryUsersIntegration.js +28 -30
- package/lib/users/createFoundryUsersIntegration.js.map +1 -1
- package/lib/users/foundryUser.d.ts +4 -2
- package/lib/users/foundryUser.d.ts.map +1 -1
- package/lib/users/foundryUser.js +69 -74
- package/lib/users/foundryUser.js.map +1 -1
- package/lib/users/index.d.ts +5 -5
- package/lib/users/index.js +5 -5
- package/lib/users/userCollectionOptions.d.ts +13 -12
- package/lib/users/userCollectionOptions.d.ts.map +1 -1
- package/lib/users/userCollectionOptions.js +82 -100
- package/lib/users/userCollectionOptions.js.map +1 -1
- package/lib/utils/AsyncIterable.d.ts +2 -0
- package/lib/utils/AsyncIterable.d.ts.map +1 -1
- package/lib/utils/AsyncIterable.js +26 -34
- package/lib/utils/AsyncIterable.js.map +1 -1
- package/lib/utils/actionTypeName.d.ts +2 -0
- package/lib/utils/actionTypeName.d.ts.map +1 -1
- package/lib/utils/actionTypeName.js +9 -7
- package/lib/utils/actionTypeName.js.map +1 -1
- package/lib/utils/chunk.d.ts +2 -0
- package/lib/utils/chunk.d.ts.map +1 -1
- package/lib/utils/chunk.js +8 -6
- package/lib/utils/chunk.js.map +1 -1
- package/package.json +21 -27
- package/lib/adapter/convertLoadSubsetOptions.test.d.ts +0 -2
- package/lib/adapter/convertLoadSubsetOptions.test.d.ts.map +0 -1
- package/lib/adapter/convertLoadSubsetOptions.test.js +0 -213
- package/lib/adapter/convertLoadSubsetOptions.test.js.map +0 -1
- package/lib/adapter/createFoundryOntologyBackendAdapter.test.d.ts +0 -2
- package/lib/adapter/createFoundryOntologyBackendAdapter.test.d.ts.map +0 -1
- package/lib/adapter/createFoundryOntologyBackendAdapter.test.js +0 -628
- package/lib/adapter/createFoundryOntologyBackendAdapter.test.js.map +0 -1
- package/lib/adapter/foundryActionValidation.test.d.ts +0 -2
- package/lib/adapter/foundryActionValidation.test.d.ts.map +0 -1
- package/lib/adapter/foundryActionValidation.test.js +0 -243
- package/lib/adapter/foundryActionValidation.test.js.map +0 -1
- package/lib/adapter/foundryCodec.test.d.ts +0 -2
- package/lib/adapter/foundryCodec.test.d.ts.map +0 -1
- package/lib/adapter/foundryCodec.test.js +0 -137
- package/lib/adapter/foundryCodec.test.js.map +0 -1
- package/lib/adapter/foundryMediaId.test.d.ts +0 -2
- package/lib/adapter/foundryMediaId.test.d.ts.map +0 -1
- package/lib/adapter/foundryMediaId.test.js +0 -23
- package/lib/adapter/foundryMediaId.test.js.map +0 -1
- package/lib/adapter/index.d.ts.map +0 -1
- package/lib/adapter/index.js.map +0 -1
- package/lib/adapter/objectCollectionOptions.test.d.ts +0 -2
- package/lib/adapter/objectCollectionOptions.test.d.ts.map +0 -1
- package/lib/adapter/objectCollectionOptions.test.js +0 -1289
- package/lib/adapter/objectCollectionOptions.test.js.map +0 -1
- package/lib/config/connectionPull.test.d.ts +0 -2
- package/lib/config/connectionPull.test.d.ts.map +0 -1
- package/lib/config/connectionPull.test.js +0 -151
- package/lib/config/connectionPull.test.js.map +0 -1
- package/lib/config/index.test.d.ts +0 -2
- package/lib/config/index.test.d.ts.map +0 -1
- package/lib/config/index.test.js +0 -182
- package/lib/config/index.test.js.map +0 -1
- package/lib/connection.test.d.ts +0 -2
- package/lib/connection.test.d.ts.map +0 -1
- package/lib/connection.test.js +0 -162
- package/lib/connection.test.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/installation/createFoundryBackendInstallation.test.d.ts +0 -2
- package/lib/installation/createFoundryBackendInstallation.test.d.ts.map +0 -1
- package/lib/installation/createFoundryBackendInstallation.test.js +0 -83
- package/lib/installation/createFoundryBackendInstallation.test.js.map +0 -1
- package/lib/installation/index.d.ts.map +0 -1
- package/lib/installation/index.js.map +0 -1
- package/lib/meta/actionTypeCollectionOptions.test.d.ts +0 -2
- package/lib/meta/actionTypeCollectionOptions.test.d.ts.map +0 -1
- package/lib/meta/actionTypeCollectionOptions.test.js +0 -24
- package/lib/meta/actionTypeCollectionOptions.test.js.map +0 -1
- package/lib/meta/actionTypeIdQuery.test.d.ts +0 -2
- package/lib/meta/actionTypeIdQuery.test.d.ts.map +0 -1
- package/lib/meta/actionTypeIdQuery.test.js +0 -131
- package/lib/meta/actionTypeIdQuery.test.js.map +0 -1
- package/lib/meta/convertActionTypeLoadSubsetOptions.test.d.ts +0 -2
- package/lib/meta/convertActionTypeLoadSubsetOptions.test.d.ts.map +0 -1
- package/lib/meta/convertActionTypeLoadSubsetOptions.test.js +0 -138
- package/lib/meta/convertActionTypeLoadSubsetOptions.test.js.map +0 -1
- package/lib/meta/convertMetaActionType.test.d.ts +0 -2
- package/lib/meta/convertMetaActionType.test.d.ts.map +0 -1
- package/lib/meta/convertMetaActionType.test.js +0 -1565
- package/lib/meta/convertMetaActionType.test.js.map +0 -1
- package/lib/meta/convertMetaLinkType.test.d.ts +0 -2
- package/lib/meta/convertMetaLinkType.test.d.ts.map +0 -1
- package/lib/meta/convertMetaLinkType.test.js +0 -110
- package/lib/meta/convertMetaLinkType.test.js.map +0 -1
- package/lib/meta/convertMetaObjectType.test.d.ts +0 -2
- package/lib/meta/convertMetaObjectType.test.d.ts.map +0 -1
- package/lib/meta/convertMetaObjectType.test.js +0 -250
- package/lib/meta/convertMetaObjectType.test.js.map +0 -1
- package/lib/meta/convertMetaQueryFunctionType.test.d.ts +0 -2
- package/lib/meta/convertMetaQueryFunctionType.test.d.ts.map +0 -1
- package/lib/meta/convertMetaQueryFunctionType.test.js +0 -134
- package/lib/meta/convertMetaQueryFunctionType.test.js.map +0 -1
- package/lib/meta/createFoundryMetaOntologyBackendAdapter.test.d.ts +0 -2
- package/lib/meta/createFoundryMetaOntologyBackendAdapter.test.d.ts.map +0 -1
- package/lib/meta/createFoundryMetaOntologyBackendAdapter.test.js +0 -49
- package/lib/meta/createFoundryMetaOntologyBackendAdapter.test.js.map +0 -1
- package/lib/meta/entityCollectionOptions.test.d.ts +0 -2
- package/lib/meta/entityCollectionOptions.test.d.ts.map +0 -1
- package/lib/meta/entityCollectionOptions.test.js +0 -98
- package/lib/meta/entityCollectionOptions.test.js.map +0 -1
- package/lib/meta/index.d.ts.map +0 -1
- package/lib/meta/index.js.map +0 -1
- package/lib/meta/loadActionTypeOmsMetadata.test.d.ts +0 -2
- package/lib/meta/loadActionTypeOmsMetadata.test.d.ts.map +0 -1
- package/lib/meta/loadActionTypeOmsMetadata.test.js +0 -218
- package/lib/meta/loadActionTypeOmsMetadata.test.js.map +0 -1
- package/lib/stagedWrites.test.d.ts +0 -2
- package/lib/stagedWrites.test.d.ts.map +0 -1
- package/lib/stagedWrites.test.js +0 -71
- package/lib/stagedWrites.test.js.map +0 -1
- package/lib/users/createFoundryUsersIntegration.test.d.ts +0 -2
- package/lib/users/createFoundryUsersIntegration.test.d.ts.map +0 -1
- package/lib/users/createFoundryUsersIntegration.test.js +0 -32
- package/lib/users/createFoundryUsersIntegration.test.js.map +0 -1
- package/lib/users/foundryUser.test.d.ts +0 -2
- package/lib/users/foundryUser.test.d.ts.map +0 -1
- package/lib/users/foundryUser.test.js +0 -45
- package/lib/users/foundryUser.test.js.map +0 -1
- package/lib/users/index.d.ts.map +0 -1
- package/lib/users/index.js.map +0 -1
- package/lib/users/userCollectionOptions.test.d.ts +0 -2
- package/lib/users/userCollectionOptions.test.d.ts.map +0 -1
- package/lib/users/userCollectionOptions.test.js +0 -18
- package/lib/users/userCollectionOptions.test.js.map +0 -1
- package/lib/utils/AsyncIterable.test.d.ts +0 -2
- package/lib/utils/AsyncIterable.test.d.ts.map +0 -1
- package/lib/utils/AsyncIterable.test.js +0 -17
- package/lib/utils/AsyncIterable.test.js.map +0 -1
- package/lib/utils/actionTypeName.test.d.ts +0 -2
- package/lib/utils/actionTypeName.test.d.ts.map +0 -1
- package/lib/utils/actionTypeName.test.js +0 -30
- package/lib/utils/actionTypeName.test.js.map +0 -1
|
@@ -1,423 +1,311 @@
|
|
|
1
|
+
import { objectCollectionOptions } from "./objectCollectionOptions.js";
|
|
2
|
+
import { toFoundryActionTypeName } from "../utils/actionTypeName.js";
|
|
3
|
+
import { getFoundryAttachmentKind } from "../meta/foundryAttachmentMetadata.js";
|
|
4
|
+
import { getFoundryActionOverrideParameterMapping } from "../meta/convertMetaActionType.js";
|
|
5
|
+
import { getFoundryValidationIssues, loadFoundrySubmissionCriteria, validateFoundryActionDraftCriteria } from "./foundryActionValidation.js";
|
|
6
|
+
import { decodeFoundryMediaId, mediaReferenceToFoundryMediaId } from "./foundryMediaId.js";
|
|
7
|
+
import { createFoundryCodec } from "./foundryCodec.js";
|
|
8
|
+
import { Actions, Attachments, MediaReferenceProperties, Queries } from "@osdk/foundry.ontologies";
|
|
9
|
+
import { Temporal } from "temporal-polyfill";
|
|
1
10
|
import { invariant } from "@bobbyfidz/panic";
|
|
2
11
|
import { MediaSets } from "@osdk/foundry.mediasets";
|
|
3
|
-
import {
|
|
4
|
-
import { certain, NonRetryableError, uncertain, } from "@party-stack/ontology";
|
|
12
|
+
import { NonRetryableError, certain, uncertain } from "@party-stack/ontology";
|
|
5
13
|
import { resolveType, unwrapType } from "@party-stack/ontology/utils";
|
|
6
|
-
|
|
7
|
-
import { getFoundryActionOverrideParameterMapping } from "../meta/convertMetaActionType.js";
|
|
8
|
-
import { getFoundryAttachmentKind } from "../meta/foundryAttachmentMetadata.js";
|
|
9
|
-
import { toFoundryActionTypeName } from "../utils/actionTypeName.js";
|
|
10
|
-
import { getFoundryValidationIssues, loadFoundrySubmissionCriteria, validateFoundryActionDraftCriteria, } from "./foundryActionValidation.js";
|
|
11
|
-
import { createFoundryCodec } from "./foundryCodec.js";
|
|
12
|
-
import { decodeFoundryMediaId, mediaReferenceToFoundryMediaId } from "./foundryMediaId.js";
|
|
13
|
-
import { objectCollectionOptions } from "./objectCollectionOptions.js";
|
|
14
|
+
//#region src/adapter/createFoundryOntologyBackendAdapter.ts
|
|
14
15
|
function isFoundryAttachmentRid(value) {
|
|
15
|
-
|
|
16
|
+
return /^ri\.attachments\.[^.]+\.attachment\..+$/.test(value);
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const foundryError = error;
|
|
22
|
-
return foundryError.statusCode === 404 || foundryError.errorCode === "NOT_FOUND";
|
|
18
|
+
function isFoundryNotFoundError(error) {
|
|
19
|
+
if (typeof error !== "object" || error === null) return false;
|
|
20
|
+
const foundryError = error;
|
|
21
|
+
return foundryError.statusCode === 404 || foundryError.errorCode === "NOT_FOUND";
|
|
23
22
|
}
|
|
24
23
|
function serializeOverrideValue(value) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (value instanceof Date) {
|
|
32
|
-
return value.toISOString();
|
|
33
|
-
}
|
|
34
|
-
if (value instanceof Temporal.Instant) {
|
|
35
|
-
return value.toString();
|
|
36
|
-
}
|
|
37
|
-
if (value instanceof Temporal.PlainDate || value instanceof Temporal.PlainDateTime) {
|
|
38
|
-
return value.toString();
|
|
39
|
-
}
|
|
40
|
-
return JSON.stringify(value) ?? "";
|
|
24
|
+
if (typeof value === "string") return value;
|
|
25
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") return String(value);
|
|
26
|
+
if (value instanceof Date) return value.toISOString();
|
|
27
|
+
if (value instanceof Temporal.Instant) return value.toString();
|
|
28
|
+
if (value instanceof Temporal.PlainDate || value instanceof Temporal.PlainDateTime) return value.toString();
|
|
29
|
+
return JSON.stringify(value) ?? "";
|
|
41
30
|
}
|
|
42
31
|
function serializeActionExecutionTime(value) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
32
|
+
try {
|
|
33
|
+
const candidate = value instanceof Date ? value.toISOString() : String(value);
|
|
34
|
+
return Temporal.Instant.from(candidate).toString();
|
|
35
|
+
} catch (cause) {
|
|
36
|
+
throw new TypeError("Invalid action execution time: expected a Date or Temporal-like ISO instant.", { cause });
|
|
37
|
+
}
|
|
50
38
|
}
|
|
51
39
|
function getApplyActionOperationId(result) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
return operationId;
|
|
40
|
+
const operationId = result.operationId;
|
|
41
|
+
if (typeof operationId !== "string" || operationId.length === 0) throw new Error("Foundry apply action response did not include an operationId.");
|
|
42
|
+
return operationId;
|
|
57
43
|
}
|
|
58
44
|
function getAttachmentName(attachment) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const name = attachment.name;
|
|
63
|
-
return typeof name === "string" ? name : undefined;
|
|
45
|
+
if (typeof attachment !== "object" || attachment === null || Array.isArray(attachment)) return;
|
|
46
|
+
const name = attachment.name;
|
|
47
|
+
return typeof name === "string" ? name : void 0;
|
|
64
48
|
}
|
|
65
49
|
function getAttachmentProviderType(target) {
|
|
66
|
-
|
|
50
|
+
return getFoundryAttachmentKind(target?.meta);
|
|
67
51
|
}
|
|
68
52
|
function getEditedObjectTypes(edits) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
for (const edit of edits.edits) {
|
|
74
|
-
if (edit.type === "addObject" || edit.type === "modifyObject" || edit.type === "deleteObject") {
|
|
75
|
-
objectTypes.add(edit.objectType);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return objectTypes;
|
|
53
|
+
const objectTypes = /* @__PURE__ */ new Set();
|
|
54
|
+
if (!edits || edits.type !== "edits") return objectTypes;
|
|
55
|
+
for (const edit of edits.edits) if (edit.type === "addObject" || edit.type === "modifyObject" || edit.type === "deleteObject") objectTypes.add(edit.objectType);
|
|
56
|
+
return objectTypes;
|
|
79
57
|
}
|
|
80
58
|
function prepareFoundryActionInvocation(options) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return {
|
|
112
|
-
parameters,
|
|
113
|
-
overrides: {
|
|
114
|
-
uniqueIdentifierLinkIdValues,
|
|
115
|
-
actionExecutionTime,
|
|
116
|
-
},
|
|
117
|
-
};
|
|
59
|
+
const actionType = options.ir.actionTypes.find((candidate) => candidate.name === options.name);
|
|
60
|
+
if (!actionType) throw new NonRetryableError(`Unknown Foundry action type "${options.name}".`);
|
|
61
|
+
const overrideMapping = getFoundryActionOverrideParameterMapping(actionType);
|
|
62
|
+
const parameterTypes = new Map(actionType.parameters.map((parameter) => [parameter.name, parameter.type]));
|
|
63
|
+
const parameters = {};
|
|
64
|
+
const uniqueIdentifierLinkIdValues = {};
|
|
65
|
+
let actionExecutionTime;
|
|
66
|
+
for (const [parameterName, value] of Object.entries(options.parameters)) {
|
|
67
|
+
if (overrideMapping.uuidByParameterName.has(parameterName)) {
|
|
68
|
+
if (value !== void 0) uniqueIdentifierLinkIdValues[overrideMapping.uuidByParameterName.get(parameterName)] = serializeOverrideValue(value);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (overrideMapping.nowParameterName === parameterName) {
|
|
72
|
+
if (value !== void 0) actionExecutionTime = serializeActionExecutionTime(value);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (value !== void 0) {
|
|
76
|
+
const parameterType = parameterTypes.get(parameterName);
|
|
77
|
+
parameters[parameterName] = parameterType ? options.codec.encodeValue(parameterType, value) : value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
parameters,
|
|
82
|
+
overrides: {
|
|
83
|
+
uniqueIdentifierLinkIdValues,
|
|
84
|
+
actionExecutionTime
|
|
85
|
+
}
|
|
86
|
+
};
|
|
118
87
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
invariant(getAttachmentProviderType(upload.target) === "media", `Foundry attachment "${upload.attachment.id}" was not materialized before action execution.`);
|
|
331
|
-
const reference = await MediaSets.uploadMedia(opts.client, upload.blob, {
|
|
332
|
-
filename: getAttachmentName(upload.blob) ?? upload.attachment.id,
|
|
333
|
-
});
|
|
334
|
-
mediaReferences.set(upload.attachment.id, reference);
|
|
335
|
-
attachmentIdMappings.push({
|
|
336
|
-
localId: upload.attachment.id,
|
|
337
|
-
remoteId: mediaReferenceToFoundryMediaId(reference),
|
|
338
|
-
});
|
|
339
|
-
}));
|
|
340
|
-
const actionCodec = createFoundryCodec(opts.ir, {
|
|
341
|
-
resolveMediaReference: (id) => mediaReferences.get(id),
|
|
342
|
-
});
|
|
343
|
-
const invocation = prepareFoundryActionInvocation({
|
|
344
|
-
ir: opts.ir,
|
|
345
|
-
name,
|
|
346
|
-
parameters,
|
|
347
|
-
codec: actionCodec,
|
|
348
|
-
});
|
|
349
|
-
let result;
|
|
350
|
-
try {
|
|
351
|
-
result = await Actions.applyWithOverrides(opts.client, opts.client.ontologyRid, toFoundryActionTypeName(name), {
|
|
352
|
-
request: {
|
|
353
|
-
options: {
|
|
354
|
-
mode: "VALIDATE_AND_EXECUTE",
|
|
355
|
-
returnEdits: "ALL_V2_WITH_DELETIONS",
|
|
356
|
-
},
|
|
357
|
-
parameters: invocation.parameters,
|
|
358
|
-
},
|
|
359
|
-
overrides: invocation.overrides,
|
|
360
|
-
},
|
|
361
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
362
|
-
{
|
|
363
|
-
preview: true,
|
|
364
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
catch (error) {
|
|
368
|
-
if (isFoundryNotFoundError(error)) {
|
|
369
|
-
throw new NonRetryableError(error instanceof Error ? error.message : "Foundry action target was not found.", { cause: error });
|
|
370
|
-
}
|
|
371
|
-
throw error;
|
|
372
|
-
}
|
|
373
|
-
if (result.validation?.result === "INVALID") {
|
|
374
|
-
throw new NonRetryableError("Invalid Action arguments.");
|
|
375
|
-
}
|
|
376
|
-
if (opts.live !== false && context) {
|
|
377
|
-
const operationId = getApplyActionOperationId(result);
|
|
378
|
-
const editedObjectTypes = Array.from(getEditedObjectTypes(result.edits));
|
|
379
|
-
const targetCollections = editedObjectTypes
|
|
380
|
-
.map((objectType) => context.objects[objectType])
|
|
381
|
-
.filter((collection) => Boolean(collection?.utils?.awaitOperationId));
|
|
382
|
-
await Promise.all(targetCollections.map((collection) => collection.utils.awaitOperationId(operationId)));
|
|
383
|
-
}
|
|
384
|
-
if (attachmentIdMappings.length === 0) {
|
|
385
|
-
return undefined;
|
|
386
|
-
}
|
|
387
|
-
return {
|
|
388
|
-
attachmentIdMappings,
|
|
389
|
-
};
|
|
390
|
-
},
|
|
391
|
-
runQueryFunction: async (name, parameters) => {
|
|
392
|
-
const queryFunctionType = opts.ir.queryFunctionTypes.find((candidate) => candidate.name === name);
|
|
393
|
-
if (!queryFunctionType) {
|
|
394
|
-
throw new Error(`Unknown Foundry query function type "${name}".`);
|
|
395
|
-
}
|
|
396
|
-
const parameterTypes = new Map(queryFunctionType.parameters.map((parameter) => [parameter.name, parameter.type]));
|
|
397
|
-
const requestParameters = {};
|
|
398
|
-
for (const [parameterName, value] of Object.entries(parameters)) {
|
|
399
|
-
if (value === undefined)
|
|
400
|
-
continue;
|
|
401
|
-
const parameterType = parameterTypes.get(parameterName);
|
|
402
|
-
requestParameters[parameterName] = parameterType
|
|
403
|
-
? codec.encodeValue(parameterType, value)
|
|
404
|
-
: value;
|
|
405
|
-
}
|
|
406
|
-
const result = await Queries.execute(opts.client, opts.client.ontologyRid, name, {
|
|
407
|
-
parameters: requestParameters,
|
|
408
|
-
});
|
|
409
|
-
return codec.decodeValue(queryFunctionType.returnType, result.value);
|
|
410
|
-
},
|
|
411
|
-
attachments,
|
|
412
|
-
};
|
|
413
|
-
return adapter;
|
|
88
|
+
function createFoundryOntologyBackendAdapter(opts) {
|
|
89
|
+
const codec = createFoundryCodec(opts.ir);
|
|
90
|
+
const adapter = {
|
|
91
|
+
name: "foundry",
|
|
92
|
+
live: opts.live !== false,
|
|
93
|
+
getCollectionOptions: (objectType) => {
|
|
94
|
+
if (opts.users?.objectType === objectType) return opts.users.getCollectionOptions(opts.client);
|
|
95
|
+
const objectTypeDef = opts.ir.objectTypes.find((ot) => ot.name === objectType);
|
|
96
|
+
return objectCollectionOptions({
|
|
97
|
+
client: opts.client,
|
|
98
|
+
objectType,
|
|
99
|
+
primaryKeyProperty: objectTypeDef.primaryKey,
|
|
100
|
+
selectedProperties: objectTypeDef.properties.map((property) => property.name),
|
|
101
|
+
live: opts.live,
|
|
102
|
+
decodeObject: (object) => codec.decodeObject(objectType, object),
|
|
103
|
+
decodeEditObject: (object) => codec.decodeEditObject(objectType, object)
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
validateAction: async (name, parameters) => {
|
|
107
|
+
const invocation = prepareFoundryActionInvocation({
|
|
108
|
+
ir: opts.ir,
|
|
109
|
+
name,
|
|
110
|
+
parameters,
|
|
111
|
+
codec
|
|
112
|
+
});
|
|
113
|
+
let result;
|
|
114
|
+
try {
|
|
115
|
+
result = await Actions.applyWithOverrides(opts.client, opts.client.ontologyRid, toFoundryActionTypeName(name), {
|
|
116
|
+
request: {
|
|
117
|
+
options: { mode: "VALIDATE_ONLY" },
|
|
118
|
+
parameters: invocation.parameters
|
|
119
|
+
},
|
|
120
|
+
overrides: invocation.overrides
|
|
121
|
+
}, { preview: true });
|
|
122
|
+
} catch (error) {
|
|
123
|
+
if (isFoundryNotFoundError(error)) throw new NonRetryableError(error instanceof Error ? error.message : "Foundry action target was not found.", { cause: error });
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
if (!result.validation) throw new Error("Foundry validate action response did not include a validation result.");
|
|
127
|
+
return {
|
|
128
|
+
certain: true,
|
|
129
|
+
value: result.validation.result === "VALID" ? {
|
|
130
|
+
kind: "ok",
|
|
131
|
+
value: void 0
|
|
132
|
+
} : {
|
|
133
|
+
kind: "err",
|
|
134
|
+
value: getFoundryValidationIssues(result)
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
},
|
|
138
|
+
validateActionDraft: async (name, parameters, live) => {
|
|
139
|
+
const actionType = opts.ir.actionTypes.find((candidate) => candidate.name === name);
|
|
140
|
+
if (!actionType) throw new NonRetryableError(`Unknown Foundry action type "${name}".`);
|
|
141
|
+
const knownParameters = /* @__PURE__ */ new Set([...Object.entries(parameters).flatMap(([parameterName, value]) => value === void 0 ? [] : [parameterName]), ...live.knownParameters]);
|
|
142
|
+
const missingKnownRequiredParameters = actionType.parameters.filter((parameter) => parameters[parameter.name] === void 0 && knownParameters.has(parameter.name) && !unwrapType(resolveType(opts.ir, parameter.type)).isOptional);
|
|
143
|
+
if (missingKnownRequiredParameters.length > 0) return certain({
|
|
144
|
+
kind: "err",
|
|
145
|
+
value: missingKnownRequiredParameters.map((parameter) => ({
|
|
146
|
+
message: `Required action parameter "${parameter.name}" is missing.`,
|
|
147
|
+
path: [parameter.name]
|
|
148
|
+
}))
|
|
149
|
+
});
|
|
150
|
+
if (!actionType.parameters.some((parameter) => parameters[parameter.name] === void 0 && !knownParameters.has(parameter.name))) return adapter.validateAction(name, parameters, live);
|
|
151
|
+
const userId = typeof live.context?.user === "string" ? live.context.user : void 0;
|
|
152
|
+
if (!userId) return uncertain();
|
|
153
|
+
const criteria = await loadFoundrySubmissionCriteria({
|
|
154
|
+
client: opts.client,
|
|
155
|
+
actionTypeName: name,
|
|
156
|
+
userId
|
|
157
|
+
});
|
|
158
|
+
return validateFoundryActionDraftCriteria({
|
|
159
|
+
client: opts.client,
|
|
160
|
+
criteria,
|
|
161
|
+
userId,
|
|
162
|
+
parameters,
|
|
163
|
+
knownParameters
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
applyAction: async (name, parameters, context) => {
|
|
167
|
+
const mediaReferences = /* @__PURE__ */ new Map();
|
|
168
|
+
const attachmentIdMappings = [];
|
|
169
|
+
await Promise.all([...new Map((context.attachmentUploads ?? []).map((upload) => [upload.attachment.id, upload])).values()].map(async (upload) => {
|
|
170
|
+
invariant(getAttachmentProviderType(upload.target) === "media", `Foundry attachment "${upload.attachment.id}" was not materialized before action execution.`);
|
|
171
|
+
const reference = await MediaSets.uploadMedia(opts.client, upload.blob, { filename: getAttachmentName(upload.blob) ?? upload.attachment.id });
|
|
172
|
+
mediaReferences.set(upload.attachment.id, reference);
|
|
173
|
+
attachmentIdMappings.push({
|
|
174
|
+
localId: upload.attachment.id,
|
|
175
|
+
remoteId: mediaReferenceToFoundryMediaId(reference)
|
|
176
|
+
});
|
|
177
|
+
}));
|
|
178
|
+
const actionCodec = createFoundryCodec(opts.ir, { resolveMediaReference: (id) => mediaReferences.get(id) });
|
|
179
|
+
const invocation = prepareFoundryActionInvocation({
|
|
180
|
+
ir: opts.ir,
|
|
181
|
+
name,
|
|
182
|
+
parameters,
|
|
183
|
+
codec: actionCodec
|
|
184
|
+
});
|
|
185
|
+
let result;
|
|
186
|
+
try {
|
|
187
|
+
result = await Actions.applyWithOverrides(opts.client, opts.client.ontologyRid, toFoundryActionTypeName(name), {
|
|
188
|
+
request: {
|
|
189
|
+
options: {
|
|
190
|
+
mode: "VALIDATE_AND_EXECUTE",
|
|
191
|
+
returnEdits: "ALL_V2_WITH_DELETIONS"
|
|
192
|
+
},
|
|
193
|
+
parameters: invocation.parameters
|
|
194
|
+
},
|
|
195
|
+
overrides: invocation.overrides
|
|
196
|
+
}, { preview: true });
|
|
197
|
+
} catch (error) {
|
|
198
|
+
if (isFoundryNotFoundError(error)) throw new NonRetryableError(error instanceof Error ? error.message : "Foundry action target was not found.", { cause: error });
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
if (result.validation?.result === "INVALID") throw new NonRetryableError("Invalid Action arguments.");
|
|
202
|
+
if (opts.live !== false && context) {
|
|
203
|
+
const operationId = getApplyActionOperationId(result);
|
|
204
|
+
const targetCollections = Array.from(getEditedObjectTypes(result.edits)).map((objectType) => context.objects[objectType]).filter((collection) => Boolean(collection?.utils?.awaitOperationId));
|
|
205
|
+
await Promise.all(targetCollections.map((collection) => collection.utils.awaitOperationId(operationId)));
|
|
206
|
+
}
|
|
207
|
+
if (attachmentIdMappings.length === 0) return;
|
|
208
|
+
return { attachmentIdMappings };
|
|
209
|
+
},
|
|
210
|
+
runQueryFunction: async (name, parameters) => {
|
|
211
|
+
const queryFunctionType = opts.ir.queryFunctionTypes.find((candidate) => candidate.name === name);
|
|
212
|
+
if (!queryFunctionType) throw new Error(`Unknown Foundry query function type "${name}".`);
|
|
213
|
+
const parameterTypes = new Map(queryFunctionType.parameters.map((parameter) => [parameter.name, parameter.type]));
|
|
214
|
+
const requestParameters = {};
|
|
215
|
+
for (const [parameterName, value] of Object.entries(parameters)) {
|
|
216
|
+
if (value === void 0) continue;
|
|
217
|
+
const parameterType = parameterTypes.get(parameterName);
|
|
218
|
+
requestParameters[parameterName] = parameterType ? codec.encodeValue(parameterType, value) : value;
|
|
219
|
+
}
|
|
220
|
+
const result = await Queries.execute(opts.client, opts.client.ontologyRid, name, { parameters: requestParameters });
|
|
221
|
+
return codec.decodeValue(queryFunctionType.returnType, result.value);
|
|
222
|
+
},
|
|
223
|
+
attachments: {
|
|
224
|
+
generateAttachmentId: (_, { target }) => {
|
|
225
|
+
invariant(target, "A property target must be passed to generateAttachmentId in the Foundry adapter so that we know whether to target attachments or media.");
|
|
226
|
+
if (getFoundryAttachmentKind(target.meta) === "attachment") return `ri.attachments.main.attachment.${crypto.randomUUID()}`;
|
|
227
|
+
return crypto.randomUUID();
|
|
228
|
+
},
|
|
229
|
+
canMaterializeAttachment: (_, { target }) => getAttachmentProviderType(target) !== "media",
|
|
230
|
+
materializeAttachment: async (attachment, blob, { target }) => {
|
|
231
|
+
invariant(target, "A property target must be passed to materializeAttachment in the Foundry adapter so that we know whether to target attachments or media.");
|
|
232
|
+
invariant(getAttachmentProviderType(target) === "attachment", "Foundry media references must be uploaded during action execution.");
|
|
233
|
+
const filename = getAttachmentName(blob) ?? "";
|
|
234
|
+
if (!isFoundryAttachmentRid(attachment.id)) {
|
|
235
|
+
const uploaded = await Attachments.upload(opts.client, blob, { filename });
|
|
236
|
+
return {
|
|
237
|
+
...attachment,
|
|
238
|
+
id: uploaded.rid
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
await Attachments.get(opts.client, attachment.id);
|
|
243
|
+
return;
|
|
244
|
+
} catch (error) {
|
|
245
|
+
if (!isFoundryNotFoundError(error)) throw error;
|
|
246
|
+
}
|
|
247
|
+
await Attachments.uploadWithRid(opts.client, attachment.id, blob, {
|
|
248
|
+
filename,
|
|
249
|
+
preview: true
|
|
250
|
+
});
|
|
251
|
+
},
|
|
252
|
+
getAttachmentContent: async (attachment) => {
|
|
253
|
+
const userContent = await opts.users?.getAttachmentContent?.(opts.client, attachment);
|
|
254
|
+
if (userContent) return userContent;
|
|
255
|
+
if (decodeFoundryMediaId(attachment.id)) {
|
|
256
|
+
const source = attachment.source;
|
|
257
|
+
invariant(source, `Foundry media attachment "${attachment.id}" is missing its object property source.`);
|
|
258
|
+
return (await MediaReferenceProperties.getMediaContent(opts.client, opts.client.ontologyRid, source.objectType, String(source.primaryKey), source.property, { preview: true })).blob();
|
|
259
|
+
}
|
|
260
|
+
return (await Attachments.read(opts.client, attachment.id)).blob();
|
|
261
|
+
},
|
|
262
|
+
getAttachmentMetadata: async (attachment, selection) => {
|
|
263
|
+
const userMetadata = await opts.users?.getAttachmentMetadata?.(opts.client, attachment, selection);
|
|
264
|
+
if (userMetadata) return userMetadata;
|
|
265
|
+
const media = decodeFoundryMediaId(attachment.id);
|
|
266
|
+
if (media) {
|
|
267
|
+
const result = {};
|
|
268
|
+
if (attachment.type !== void 0) result.type = attachment.type;
|
|
269
|
+
if (selection.includes("dimensions")) {
|
|
270
|
+
const detailed = await MediaSets.metadata(opts.client, media.mediaSetRid, media.mediaItemRid);
|
|
271
|
+
result.size = detailed.sizeBytes;
|
|
272
|
+
if (detailed.type === "imagery" && detailed.dimensions) result.dimensions = {
|
|
273
|
+
width: detailed.dimensions.width,
|
|
274
|
+
height: detailed.dimensions.height
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
if (!selection.filter((field) => result[field] === void 0).some((field) => field !== "dimensions")) return result;
|
|
278
|
+
const source = attachment.source;
|
|
279
|
+
invariant(source, `Foundry media attachment "${attachment.id}" is missing its object property source.`);
|
|
280
|
+
const info = await MediaReferenceProperties.getMediaMetadata(opts.client, opts.client.ontologyRid, source.objectType, String(source.primaryKey), source.property, { preview: true });
|
|
281
|
+
return {
|
|
282
|
+
...result,
|
|
283
|
+
size: Number(info.sizeBytes),
|
|
284
|
+
type: info.mediaType,
|
|
285
|
+
name: info.path
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
const metadata = await Attachments.get(opts.client, attachment.id);
|
|
289
|
+
return {
|
|
290
|
+
id: attachment.id,
|
|
291
|
+
size: Number(metadata.sizeBytes),
|
|
292
|
+
type: metadata.mediaType,
|
|
293
|
+
name: metadata.filename
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
return adapter;
|
|
414
299
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
300
|
+
function createFoundryOntologyBackend(opts) {
|
|
301
|
+
return async (ir, context) => createFoundryOntologyBackendAdapter({
|
|
302
|
+
ir,
|
|
303
|
+
client: "client" in opts ? opts.client : await opts.createClient(ir, context),
|
|
304
|
+
users: opts.users,
|
|
305
|
+
live: opts.live
|
|
306
|
+
});
|
|
422
307
|
}
|
|
308
|
+
//#endregion
|
|
309
|
+
export { createFoundryOntologyBackend, createFoundryOntologyBackendAdapter, isFoundryNotFoundError };
|
|
310
|
+
|
|
423
311
|
//# sourceMappingURL=createFoundryOntologyBackendAdapter.js.map
|