@openfairygui/functions 0.2.0-alpha.0 → 0.2.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/restore.ts CHANGED
@@ -757,9 +757,16 @@ class RestoreWorkflow {
757
757
  ): Promise<RestorableResource | null> {
758
758
  const resources = pkg.listResources() as RestorableResource[];
759
759
  const existing = this._findResourceByFile(resources, owner, 'ImageResource', fileName);
760
- if (existing) return existing;
761
760
  const sourcePath = await this._resolveLooseSourceFile(pkg, sourceDir, fileName);
762
- if (!sourcePath) return null;
761
+ if (!sourcePath) return existing ?? null;
762
+ if (existing) {
763
+ existing.setExtras?.({
764
+ ...(existing.getExtras?.() ?? {}),
765
+ _publishedFile: fileBaseName(sourcePath),
766
+ _restoreAsLooseImage: true,
767
+ });
768
+ return existing;
769
+ }
763
770
  const resource = doc.createImageResource(stripExtension(fileName));
764
771
  resource
765
772
  .setId(generateId())
@@ -772,7 +779,7 @@ class RestoreWorkflow {
772
779
  ...(resource.getExtras?.() ?? {}),
773
780
  _publishedFile: fileBaseName(sourcePath),
774
781
  _suppressPackageSize: true,
775
- _syntheticLooseImage: true,
782
+ _restoreAsLooseImage: true,
776
783
  });
777
784
  pkg.addResource(resource);
778
785
  return resource as RestorableResource;
@@ -1022,8 +1029,8 @@ class RestoreWorkflow {
1022
1029
  warnings: string[],
1023
1030
  ): Promise<void> {
1024
1031
  for (const resource of pkg.listResources() as RestorableResource[]) {
1025
- const syntheticLooseImage = resource.getExtras?.()?._syntheticLooseImage === true;
1026
- if (!['SoundResource', 'MiscResource', 'SpineResource', 'DragonBonesResource'].includes(resource.propertyType) && !syntheticLooseImage) {
1032
+ const restoreAsLooseImage = resource.getExtras?.()?._restoreAsLooseImage === true;
1033
+ if (!['SoundResource', 'MiscResource', 'SpineResource', 'DragonBonesResource'].includes(resource.propertyType) && !restoreAsLooseImage) {
1027
1034
  continue;
1028
1035
  }
1029
1036
  const fileName = resourceFileName(resource);
@@ -41,6 +41,7 @@ export interface PublishDependency {
41
41
 
42
42
  export interface PackagePublishArtifactsExtras extends ExtrasMap {
43
43
  publishedResourceIds?: string[];
44
+ exportedResourceIds?: string[];
44
45
  publishedIncludeBranches?: boolean;
45
46
  publishedEffectiveResourceIds?: Record<string, string>;
46
47
  }
@@ -6,7 +6,7 @@ import {
6
6
  type UamTransactionOperation,
7
7
  type UamTransactionSupportIssue,
8
8
  type UamValidationIssue,
9
- } from '@openfairygui/core';
9
+ } from '@openfairygui/core/uam';
10
10
 
11
11
  export interface ApplyUamTransactionAppInput {
12
12
  project: UamProject;
@@ -20,8 +20,10 @@ export interface ApplyUamTransactionAppError {
20
20
  opIndex?: number;
21
21
  opId?: string;
22
22
  opKind?: UamTransactionOperation['kind'];
23
+ operationKind?: UamTransactionOperation['kind'];
23
24
  selector?: Record<string, unknown>;
24
25
  issues?: UamValidationIssue[] | UamTransactionSupportIssue[];
26
+ diagnostics: ApplyUamTransactionAppDiagnostic[];
25
27
  }
26
28
 
27
29
  export type ApplyUamTransactionAppResult =
@@ -41,6 +43,70 @@ function mapTransactionErrorStage(error: UamTransactionError): ApplyUamTransacti
41
43
  }
42
44
  }
43
45
 
46
+ export interface ApplyUamTransactionAppDiagnostic {
47
+ code: string;
48
+ message: string;
49
+ severity: 'error';
50
+ path?: string;
51
+ nodeKind?: string;
52
+ resourceKind?: string;
53
+ gearKind?: string;
54
+ field?: string;
55
+ operationKind?: UamTransactionOperation['kind'];
56
+ opIndex?: number;
57
+ opId?: string;
58
+ }
59
+
60
+ function compactDiagnostic(diagnostic: ApplyUamTransactionAppDiagnostic): ApplyUamTransactionAppDiagnostic {
61
+ return Object.fromEntries(Object.entries(diagnostic).filter(([, value]) => value !== undefined)) as ApplyUamTransactionAppDiagnostic;
62
+ }
63
+
64
+ function isTransactionSupportIssue(issue: UamValidationIssue | UamTransactionSupportIssue): issue is UamTransactionSupportIssue {
65
+ return 'code' in issue;
66
+ }
67
+
68
+ function mapTransactionDiagnostics(error: UamTransactionError): ApplyUamTransactionAppDiagnostic[] {
69
+ if (error.issues?.length) {
70
+ return error.issues.map((issue) => {
71
+ if (isTransactionSupportIssue(issue)) {
72
+ return compactDiagnostic({
73
+ code: issue.code,
74
+ message: issue.message,
75
+ severity: 'error' as const,
76
+ path: issue.path,
77
+ nodeKind: issue.nodeKind,
78
+ resourceKind: issue.resourceKind,
79
+ gearKind: issue.gearKind,
80
+ field: issue.field,
81
+ operationKind: issue.operationKind ?? error.opKind,
82
+ opIndex: error.opIndex,
83
+ opId: error.opId,
84
+ });
85
+ }
86
+ return compactDiagnostic({
87
+ code: error.code,
88
+ message: issue.message,
89
+ severity: 'error' as const,
90
+ path: issue.path,
91
+ operationKind: error.opKind,
92
+ opIndex: error.opIndex,
93
+ opId: error.opId,
94
+ });
95
+ });
96
+ }
97
+ return [
98
+ compactDiagnostic({
99
+ code: error.code,
100
+ message: error.message,
101
+ severity: 'error',
102
+ path: error.opIndex === undefined ? undefined : `operations[${error.opIndex}]`,
103
+ operationKind: error.opKind,
104
+ opIndex: error.opIndex,
105
+ opId: error.opId,
106
+ }),
107
+ ];
108
+ }
109
+
44
110
  export function applyUamTransactionApp(input: ApplyUamTransactionAppInput): ApplyUamTransactionAppResult {
45
111
  try {
46
112
  return {
@@ -58,8 +124,10 @@ export function applyUamTransactionApp(input: ApplyUamTransactionAppInput): Appl
58
124
  opIndex: error.opIndex,
59
125
  opId: error.opId,
60
126
  opKind: error.opKind,
127
+ operationKind: error.opKind,
61
128
  selector: error.selector,
62
129
  issues: error.issues,
130
+ diagnostics: mapTransactionDiagnostics(error),
63
131
  },
64
132
  };
65
133
  }
package/src/utils.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import type { Transform } from '@openfairygui/core';
2
2
 
3
+ export type TextureSetMode =
4
+ | { kind: 'auto'; raw: string }
5
+ | { kind: 'standalone'; raw: string; sizeMode: 'default' | 'npot' | 'multipleOf4' }
6
+ | { kind: 'page'; raw: string; pageIndex: number };
7
+
3
8
  /**
4
9
  * Wraps a transform function, assigning it a name for the transform stack.
5
10
  */
@@ -7,3 +12,26 @@ export function createTransform(name: string, fn: Transform): Transform {
7
12
  Object.defineProperty(fn, 'name', { value: name });
8
13
  return fn;
9
14
  }
15
+
16
+ export function parseTextureSetMode(value: string | null | undefined): TextureSetMode {
17
+ const raw = value?.trim() ?? '';
18
+ if (!raw) {
19
+ return { kind: 'auto', raw: '' };
20
+ }
21
+ if (raw === 'alone') {
22
+ return { kind: 'standalone', raw, sizeMode: 'default' };
23
+ }
24
+ if (raw === 'alone_npot') {
25
+ return { kind: 'standalone', raw, sizeMode: 'npot' };
26
+ }
27
+ if (raw === 'alone_mof') {
28
+ return { kind: 'standalone', raw, sizeMode: 'multipleOf4' };
29
+ }
30
+ if (/^\d+$/.test(raw)) {
31
+ const pageIndex = Number(raw);
32
+ if (pageIndex >= 0 && pageIndex <= 10) {
33
+ return { kind: 'page', raw, pageIndex };
34
+ }
35
+ }
36
+ return { kind: 'auto', raw };
37
+ }