@bsv/dpp-profiles 0.3.0-beta.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/LICENSE +58 -0
- package/README.md +64 -0
- package/dist/applicability.d.ts +96 -0
- package/dist/applicability.d.ts.map +1 -0
- package/dist/applicability.js +181 -0
- package/dist/applicability.js.map +1 -0
- package/dist/combinations.d.ts +30 -0
- package/dist/combinations.d.ts.map +1 -0
- package/dist/combinations.js +103 -0
- package/dist/combinations.js.map +1 -0
- package/dist/evidence-shapes.d.ts +198 -0
- package/dist/evidence-shapes.d.ts.map +1 -0
- package/dist/evidence-shapes.js +123 -0
- package/dist/evidence-shapes.js.map +1 -0
- package/dist/gs1-epc-binary.d.ts +81 -0
- package/dist/gs1-epc-binary.d.ts.map +1 -0
- package/dist/gs1-epc-binary.js +252 -0
- package/dist/gs1-epc-binary.js.map +1 -0
- package/dist/gs1-resolution.d.ts +392 -0
- package/dist/gs1-resolution.d.ts.map +1 -0
- package/dist/gs1-resolution.js +696 -0
- package/dist/gs1-resolution.js.map +1 -0
- package/dist/identifiers.d.ts +57 -0
- package/dist/identifiers.d.ts.map +1 -0
- package/dist/identifiers.js +117 -0
- package/dist/identifiers.js.map +1 -0
- package/dist/index.d.ts +235 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +124 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest-v2.d.ts +87 -0
- package/dist/manifest-v2.d.ts.map +1 -0
- package/dist/manifest-v2.js +31 -0
- package/dist/manifest-v2.js.map +1 -0
- package/dist/mapping.d.ts +84 -0
- package/dist/mapping.d.ts.map +1 -0
- package/dist/mapping.js +88 -0
- package/dist/mapping.js.map +1 -0
- package/dist/projections.d.ts +233 -0
- package/dist/projections.d.ts.map +1 -0
- package/dist/projections.js +466 -0
- package/dist/projections.js.map +1 -0
- package/frozen.json +42 -0
- package/generated/consumer/battery-v2.json +2248 -0
- package/generated/consumer/battery-v3.json +4354 -0
- package/generated/consumer/general-v1.json +9 -0
- package/generated/consumer/general-v2.json +714 -0
- package/generated/consumer/textile-v1.json +101 -0
- package/generated/consumer/textile-v2.json +1033 -0
- package/generated/consumer/textile-v3.json +2011 -0
- package/generated/index.json +86 -0
- package/generated/mapping/battery@2.md +116 -0
- package/generated/mapping/battery@3.md +130 -0
- package/generated/mapping/general@2.md +50 -0
- package/generated/mapping/textile@2.md +61 -0
- package/generated/mapping/textile@3.md +73 -0
- package/generated/payload-schema/battery@2.public.schema.json +609 -0
- package/generated/payload-schema/battery@2.restricted.schema.json +377 -0
- package/generated/payload-schema/battery@3.public.schema.json +1364 -0
- package/generated/payload-schema/battery@3.restricted.schema.json +1097 -0
- package/generated/payload-schema/general@1.public.schema.json +37 -0
- package/generated/payload-schema/general@1.restricted.schema.json +9 -0
- package/generated/payload-schema/general@2.public.schema.json +352 -0
- package/generated/payload-schema/general@2.restricted.schema.json +52 -0
- package/generated/payload-schema/textile@1.public.schema.json +82 -0
- package/generated/payload-schema/textile@1.restricted.schema.json +22 -0
- package/generated/payload-schema/textile@2.public.schema.json +464 -0
- package/generated/payload-schema/textile@2.restricted.schema.json +78 -0
- package/generated/payload-schema/textile@3.public.schema.json +1299 -0
- package/generated/payload-schema/textile@3.restricted.schema.json +78 -0
- package/manifests/battery@2.json +4047 -0
- package/manifests/battery@3.json +6164 -0
- package/manifests/exchange/untp-0.7.0-jose@1.json +191 -0
- package/manifests/exchange/vc-di-ecdsa-rdfc-2019@1.json +74 -0
- package/manifests/exchange/vsc-draft-compat@0.1.0.json +64 -0
- package/manifests/general@1.json +148 -0
- package/manifests/general@2.json +1266 -0
- package/manifests/interoperability/epcis-json@1.json +69 -0
- package/manifests/interoperability/epcis-vsc@1.json +64 -0
- package/manifests/interoperability/gs1-digital-link@1.json +71 -0
- package/manifests/operator/federated-operators@1.json +54 -0
- package/manifests/operator/single-operator@1.json +52 -0
- package/manifests/textile@1.json +383 -0
- package/manifests/textile@2.json +1682 -0
- package/manifests/textile@3.json +2763 -0
- package/package.json +59 -0
- package/schemas/exchange-profile.schema.json +134 -0
- package/schemas/gs1/NOTICE.md +11 -0
- package/schemas/gs1/resolver-description-file-schema-1.2.0.json +124 -0
- package/schemas/gs1/resolver-linkset-context-1.2.1.jsonld +39 -0
- package/schemas/gs1/resolver-linkset-schema-1.2.1.json +96 -0
- package/schemas/interoperability-profile.schema.json +347 -0
- package/schemas/operator-profile.schema.json +108 -0
- package/schemas/product-identity.schema.json +45 -0
- package/schemas/profile-manifest-v2.schema.json +1087 -0
- package/schemas/profile-manifest.schema.json +291 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared evidence, measurement, document, language and date shapes
|
|
3
|
+
* (`contracts/profile-evidence.schema.json`, `spec/passport-projections.md`
|
|
4
|
+
* §5), with the few pure helpers a projection and a profile validator need:
|
|
5
|
+
* which precision a date carries, which language of a text to return, when a
|
|
6
|
+
* warranty expiry can be derived from evidence and when it cannot, and which
|
|
7
|
+
* unit conversions are explicit enough to make. None of these guesses. A
|
|
8
|
+
* month is never given a day, a fraction is never read as a percent without
|
|
9
|
+
* its basis saying so, and a missing start date yields no expiry.
|
|
10
|
+
*/
|
|
11
|
+
export type DatePrecision = 'day' | 'month' | 'year';
|
|
12
|
+
export interface PreciseDate {
|
|
13
|
+
date: string;
|
|
14
|
+
precision: DatePrecision;
|
|
15
|
+
}
|
|
16
|
+
export type EvidenceGranularity = 'model' | 'batch' | 'item' | 'component';
|
|
17
|
+
export type AccessScope = 'public' | 'owner' | 'legitimate' | 'authority';
|
|
18
|
+
export interface SubjectRef {
|
|
19
|
+
id: string;
|
|
20
|
+
granularity: EvidenceGranularity;
|
|
21
|
+
componentRef?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface SourceRef {
|
|
24
|
+
kind: 'source-revision' | 'credential' | 'document';
|
|
25
|
+
id: string;
|
|
26
|
+
revisionId?: string;
|
|
27
|
+
digest?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface RelevantTime {
|
|
30
|
+
at?: string;
|
|
31
|
+
from?: string;
|
|
32
|
+
until?: string;
|
|
33
|
+
precision: DatePrecision;
|
|
34
|
+
}
|
|
35
|
+
export interface ClaimEvidence {
|
|
36
|
+
property: string;
|
|
37
|
+
subject: SubjectRef;
|
|
38
|
+
source: SourceRef;
|
|
39
|
+
reporter?: string;
|
|
40
|
+
issuer?: string;
|
|
41
|
+
relevantTime?: RelevantTime;
|
|
42
|
+
reportRef?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface RelatedDocument {
|
|
45
|
+
ref: string;
|
|
46
|
+
purpose: string;
|
|
47
|
+
url?: string;
|
|
48
|
+
mediaType?: string;
|
|
49
|
+
language?: string;
|
|
50
|
+
revision?: string;
|
|
51
|
+
date?: string;
|
|
52
|
+
precision?: DatePrecision;
|
|
53
|
+
digest?: string;
|
|
54
|
+
byteLength?: number;
|
|
55
|
+
retained: boolean;
|
|
56
|
+
access: AccessScope;
|
|
57
|
+
}
|
|
58
|
+
export interface Certification {
|
|
59
|
+
scheme: {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
version?: string;
|
|
63
|
+
};
|
|
64
|
+
certificateId: string;
|
|
65
|
+
issuer: string;
|
|
66
|
+
subject: SubjectRef;
|
|
67
|
+
validFrom?: string;
|
|
68
|
+
validUntil?: string;
|
|
69
|
+
precision?: DatePrecision;
|
|
70
|
+
documentRef?: RelatedDocument;
|
|
71
|
+
credentialRef?: {
|
|
72
|
+
id: string;
|
|
73
|
+
digest?: string;
|
|
74
|
+
};
|
|
75
|
+
verification: {
|
|
76
|
+
status: 'verified' | 'failed' | 'unknown' | 'not-checked';
|
|
77
|
+
checkedAt?: string;
|
|
78
|
+
reportRef?: string;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export type MeasurementBasis = 'fraction' | 'percent' | 'mass' | 'count' | 'per-functional-unit';
|
|
82
|
+
export interface MeasurementConversion {
|
|
83
|
+
fromUnit: string;
|
|
84
|
+
toUnit: string;
|
|
85
|
+
rule: string;
|
|
86
|
+
explicit: true;
|
|
87
|
+
}
|
|
88
|
+
export interface Measurement {
|
|
89
|
+
property: string;
|
|
90
|
+
value: number | string;
|
|
91
|
+
unit: string;
|
|
92
|
+
basis?: MeasurementBasis;
|
|
93
|
+
functionalUnit?: string;
|
|
94
|
+
denominator?: {
|
|
95
|
+
value: number;
|
|
96
|
+
unit: string;
|
|
97
|
+
};
|
|
98
|
+
method?: {
|
|
99
|
+
id: string;
|
|
100
|
+
version?: string;
|
|
101
|
+
};
|
|
102
|
+
boundary?: string;
|
|
103
|
+
conditions?: string;
|
|
104
|
+
measuredAt?: PreciseDate;
|
|
105
|
+
effective?: {
|
|
106
|
+
from?: string;
|
|
107
|
+
until?: string;
|
|
108
|
+
};
|
|
109
|
+
subject: SubjectRef;
|
|
110
|
+
evidence?: ClaimEvidence[];
|
|
111
|
+
conversion?: MeasurementConversion;
|
|
112
|
+
}
|
|
113
|
+
export interface LocalisedValue {
|
|
114
|
+
language: string;
|
|
115
|
+
text: string;
|
|
116
|
+
}
|
|
117
|
+
export type LanguageSelection = 'exact' | 'base' | 'default';
|
|
118
|
+
export interface LocalisedText {
|
|
119
|
+
values: LocalisedValue[];
|
|
120
|
+
returnedLanguage?: string;
|
|
121
|
+
selection?: LanguageSelection;
|
|
122
|
+
}
|
|
123
|
+
export interface WarrantyTerms {
|
|
124
|
+
duration: {
|
|
125
|
+
value: number;
|
|
126
|
+
unit: 'months' | 'years';
|
|
127
|
+
};
|
|
128
|
+
calendarRule: 'purchase-date' | 'manufacture-date' | 'first-use';
|
|
129
|
+
conditions?: string;
|
|
130
|
+
}
|
|
131
|
+
export interface WarrantyStart {
|
|
132
|
+
date: string;
|
|
133
|
+
precision: DatePrecision;
|
|
134
|
+
evidenceRef: string;
|
|
135
|
+
}
|
|
136
|
+
export interface WarrantyExpiry {
|
|
137
|
+
start: WarrantyStart;
|
|
138
|
+
terms: WarrantyTerms;
|
|
139
|
+
derived: {
|
|
140
|
+
date: string;
|
|
141
|
+
precision: DatePrecision;
|
|
142
|
+
rule: string;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The precision a date string carries, or undefined when it is not a real
|
|
147
|
+
* calendar date at any of the three precisions. `2026-02-30` is undefined,
|
|
148
|
+
* not a February day rounded to something.
|
|
149
|
+
*/
|
|
150
|
+
export declare function datePrecisionOf(text: string): DatePrecision | undefined;
|
|
151
|
+
/** The primary language subtag of a BCP 47 tag, lower-cased: `de` of `de-CH`. */
|
|
152
|
+
export declare function baseLanguage(tag: string): string;
|
|
153
|
+
/**
|
|
154
|
+
* Which of a text's languages to return: the exact tag the reader asked for,
|
|
155
|
+
* then any value in the reader's base language (or the base of the exact
|
|
156
|
+
* tag), then the declared default. The selection is recorded so a surface
|
|
157
|
+
* can say which it got; a value is never rewritten into another language.
|
|
158
|
+
* Undefined when none of the three matches, which a caller reports rather
|
|
159
|
+
* than papering over with the first value.
|
|
160
|
+
*/
|
|
161
|
+
export declare function selectLanguage(values: readonly LocalisedValue[], locale: {
|
|
162
|
+
exact?: string;
|
|
163
|
+
base?: string;
|
|
164
|
+
default: string;
|
|
165
|
+
}): {
|
|
166
|
+
text: string;
|
|
167
|
+
language: string;
|
|
168
|
+
selection: LanguageSelection;
|
|
169
|
+
} | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* A warranty expiry from an evidenced start and the model's terms, at the
|
|
172
|
+
* precision the start permits: a day start yields a day (month ends clamped,
|
|
173
|
+
* so 31 January plus one month is 28 or 29 February), a month start yields a
|
|
174
|
+
* month, a year start yields a year and only for whole years. No start, a
|
|
175
|
+
* start whose text does not match its precision, or a duration a year cannot
|
|
176
|
+
* place, yields a reason and no date. Terms alone never yield an expiry.
|
|
177
|
+
*/
|
|
178
|
+
export declare function deriveWarrantyExpiry(start: WarrantyStart | undefined, terms: WarrantyTerms): {
|
|
179
|
+
expiry: WarrantyExpiry;
|
|
180
|
+
} | {
|
|
181
|
+
reason: string;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* The one conversion explicit enough to make without a method: a fraction
|
|
185
|
+
* whose basis says it is a fraction, to a percent. Everything else is
|
|
186
|
+
* refused with the reason, because a bare number does not say whether 0.5
|
|
187
|
+
* is a half or half a percent, and a mass-balance share is not a physical
|
|
188
|
+
* share. A converted measurement keeps its source unit in `conversion`.
|
|
189
|
+
*/
|
|
190
|
+
export declare function convertMeasurement(measurement: Measurement, target: {
|
|
191
|
+
unit: string;
|
|
192
|
+
basis?: MeasurementBasis;
|
|
193
|
+
}): {
|
|
194
|
+
measurement: Measurement;
|
|
195
|
+
} | {
|
|
196
|
+
reason: string;
|
|
197
|
+
};
|
|
198
|
+
//# sourceMappingURL=evidence-shapes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evidence-shapes.d.ts","sourceRoot":"","sources":["../src/evidence-shapes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,CAAA;AACpD,MAAM,WAAW,WAAW;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,aAAa,CAAA;CAAE;AACvE,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,WAAW,CAAA;AAC1E,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,YAAY,GAAG,WAAW,CAAA;AAEzE,MAAM,WAAW,UAAU;IAAG,EAAE,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,mBAAmB,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE;AACnG,MAAM,WAAW,SAAS;IAAG,IAAI,EAAE,iBAAiB,GAAG,YAAY,GAAG,UAAU,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAA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CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,iBAAiB,CAAA;CAAE,GAAG,SAAS,CAc1M;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,EAAE,KAAK,EAAE,aAAa,GAAG;IAAE,MAAM,EAAE,cAAc,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAoB5I;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,gBAAgB,CAAA;CAAE,GAAG;IAAE,WAAW,EAAE,WAAW,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAgBlK"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared evidence, measurement, document, language and date shapes
|
|
3
|
+
* (`contracts/profile-evidence.schema.json`, `spec/passport-projections.md`
|
|
4
|
+
* §5), with the few pure helpers a projection and a profile validator need:
|
|
5
|
+
* which precision a date carries, which language of a text to return, when a
|
|
6
|
+
* warranty expiry can be derived from evidence and when it cannot, and which
|
|
7
|
+
* unit conversions are explicit enough to make. None of these guesses. A
|
|
8
|
+
* month is never given a day, a fraction is never read as a percent without
|
|
9
|
+
* its basis saying so, and a missing start date yields no expiry.
|
|
10
|
+
*/
|
|
11
|
+
const DAY = /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
|
|
12
|
+
const MONTH = /^(\d{4})-(0[1-9]|1[0-2])$/;
|
|
13
|
+
const YEAR = /^\d{4}$/;
|
|
14
|
+
function daysInMonth(year, month) {
|
|
15
|
+
return new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The precision a date string carries, or undefined when it is not a real
|
|
19
|
+
* calendar date at any of the three precisions. `2026-02-30` is undefined,
|
|
20
|
+
* not a February day rounded to something.
|
|
21
|
+
*/
|
|
22
|
+
export function datePrecisionOf(text) {
|
|
23
|
+
if (YEAR.test(text))
|
|
24
|
+
return 'year';
|
|
25
|
+
if (MONTH.test(text))
|
|
26
|
+
return 'month';
|
|
27
|
+
const day = DAY.exec(text);
|
|
28
|
+
if (day == null)
|
|
29
|
+
return undefined;
|
|
30
|
+
const [, y, m, d] = day;
|
|
31
|
+
return Number(d) <= daysInMonth(Number(y), Number(m)) ? 'day' : undefined;
|
|
32
|
+
}
|
|
33
|
+
/** The primary language subtag of a BCP 47 tag, lower-cased: `de` of `de-CH`. */
|
|
34
|
+
export function baseLanguage(tag) {
|
|
35
|
+
return tag.split('-')[0].toLowerCase();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Which of a text's languages to return: the exact tag the reader asked for,
|
|
39
|
+
* then any value in the reader's base language (or the base of the exact
|
|
40
|
+
* tag), then the declared default. The selection is recorded so a surface
|
|
41
|
+
* can say which it got; a value is never rewritten into another language.
|
|
42
|
+
* Undefined when none of the three matches, which a caller reports rather
|
|
43
|
+
* than papering over with the first value.
|
|
44
|
+
*/
|
|
45
|
+
export function selectLanguage(values, locale) {
|
|
46
|
+
const lower = (tag) => tag.toLowerCase();
|
|
47
|
+
if (locale.exact != null) {
|
|
48
|
+
const exact = values.find((v) => lower(v.language) === lower(locale.exact));
|
|
49
|
+
if (exact != null)
|
|
50
|
+
return { text: exact.text, language: exact.language, selection: 'exact' };
|
|
51
|
+
}
|
|
52
|
+
const base = locale.base != null ? baseLanguage(locale.base) : locale.exact != null ? baseLanguage(locale.exact) : undefined;
|
|
53
|
+
if (base != null) {
|
|
54
|
+
const match = values.find((v) => baseLanguage(v.language) === base);
|
|
55
|
+
if (match != null)
|
|
56
|
+
return { text: match.text, language: match.language, selection: 'base' };
|
|
57
|
+
}
|
|
58
|
+
const fallback = values.find((v) => lower(v.language) === lower(locale.default)) ?? values.find((v) => baseLanguage(v.language) === baseLanguage(locale.default));
|
|
59
|
+
if (fallback != null)
|
|
60
|
+
return { text: fallback.text, language: fallback.language, selection: 'default' };
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A warranty expiry from an evidenced start and the model's terms, at the
|
|
65
|
+
* precision the start permits: a day start yields a day (month ends clamped,
|
|
66
|
+
* so 31 January plus one month is 28 or 29 February), a month start yields a
|
|
67
|
+
* month, a year start yields a year and only for whole years. No start, a
|
|
68
|
+
* start whose text does not match its precision, or a duration a year cannot
|
|
69
|
+
* place, yields a reason and no date. Terms alone never yield an expiry.
|
|
70
|
+
*/
|
|
71
|
+
export function deriveWarrantyExpiry(start, terms) {
|
|
72
|
+
if (start == null)
|
|
73
|
+
return { reason: `no evidenced ${terms.calendarRule} start; the model's terms alone give no expiry` };
|
|
74
|
+
if (datePrecisionOf(start.date) !== start.precision)
|
|
75
|
+
return { reason: `the start ${start.date} is not a ${start.precision}-precision date` };
|
|
76
|
+
if (!Number.isInteger(terms.duration.value) || terms.duration.value < 1)
|
|
77
|
+
return { reason: 'the warranty duration is not a positive whole number' };
|
|
78
|
+
const months = terms.duration.unit === 'years' ? terms.duration.value * 12 : terms.duration.value;
|
|
79
|
+
const label = `${terms.calendarRule} plus ${terms.duration.value} ${terms.duration.unit}`;
|
|
80
|
+
if (start.precision === 'year') {
|
|
81
|
+
if (months % 12 !== 0)
|
|
82
|
+
return { reason: `a year-precision start cannot place ${months} months in a year; the expiry stays underived` };
|
|
83
|
+
return { expiry: { start, terms, derived: { date: String(Number(start.date) + months / 12), precision: 'year', rule: `${label}, year precision` } } };
|
|
84
|
+
}
|
|
85
|
+
const [y, m, d] = start.date.split('-').map(Number);
|
|
86
|
+
const total = (y * 12 + (m - 1)) + months;
|
|
87
|
+
const year = Math.floor(total / 12);
|
|
88
|
+
const month = (total % 12) + 1;
|
|
89
|
+
const mm = String(month).padStart(2, '0');
|
|
90
|
+
if (start.precision === 'month') {
|
|
91
|
+
return { expiry: { start, terms, derived: { date: `${year}-${mm}`, precision: 'month', rule: `${label}, month precision; no day is invented` } } };
|
|
92
|
+
}
|
|
93
|
+
const day = Math.min(d, daysInMonth(year, month));
|
|
94
|
+
return { expiry: { start, terms, derived: { date: `${year}-${mm}-${String(day).padStart(2, '0')}`, precision: 'day', rule: `${label}, day precision, month end clamped` } } };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The one conversion explicit enough to make without a method: a fraction
|
|
98
|
+
* whose basis says it is a fraction, to a percent. Everything else is
|
|
99
|
+
* refused with the reason, because a bare number does not say whether 0.5
|
|
100
|
+
* is a half or half a percent, and a mass-balance share is not a physical
|
|
101
|
+
* share. A converted measurement keeps its source unit in `conversion`.
|
|
102
|
+
*/
|
|
103
|
+
export function convertMeasurement(measurement, target) {
|
|
104
|
+
if (typeof measurement.value !== 'number')
|
|
105
|
+
return { reason: 'a textual value cannot be converted' };
|
|
106
|
+
if (measurement.unit === target.unit && (target.basis == null || measurement.basis === target.basis))
|
|
107
|
+
return { measurement };
|
|
108
|
+
if (measurement.basis === 'fraction' && target.basis === 'percent') {
|
|
109
|
+
return {
|
|
110
|
+
measurement: {
|
|
111
|
+
...measurement,
|
|
112
|
+
value: measurement.value * 100,
|
|
113
|
+
unit: target.unit,
|
|
114
|
+
basis: 'percent',
|
|
115
|
+
conversion: { fromUnit: measurement.unit, toUnit: target.unit, rule: 'fraction to percent: multiplied by 100', explicit: true },
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (measurement.basis == null)
|
|
120
|
+
return { reason: `no basis is declared for ${measurement.property}, so ${measurement.unit} cannot be read as ${target.unit}` };
|
|
121
|
+
return { reason: `no explicit conversion from ${measurement.basis} in ${measurement.unit} to ${target.basis ?? 'an undeclared basis'} in ${target.unit}` };
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=evidence-shapes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evidence-shapes.js","sourceRoot":"","sources":["../src/evidence-shapes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA8EH,MAAM,GAAG,GAAG,iDAAiD,CAAA;AAC7D,MAAM,KAAK,GAAG,2BAA2B,CAAA;AACzC,MAAM,IAAI,GAAG,SAAS,CAAA;AAEtB,SAAS,WAAW,CAAC,IAAY,EAAE,KAAa;IAC9C,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAA;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,MAAM,CAAA;IAClC,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,OAAO,CAAA;IACpC,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC1B,IAAI,GAAG,IAAI,IAAI;QAAE,OAAO,SAAS,CAAA;IACjC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAA;IACvB,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AAC3E,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,CAAA;AACzC,CAAC;AAED;;;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AAE,MAAM,EAAE,4BAA4B,WAAW,CAAC,QAAQ,QAAQ,WAAW,CAAC,IAAI,sBAAsB,MAAM,CAAC,IAAI,EAAE,EAAE,CAAA;IAC7J,OAAO,EAAE,MAAM,EAAE,+BAA+B,WAAW,CAAC,KAAK,OAAO,WAAW,CAAC,IAAI,OAAO,MAAM,CAAC,KAAK,IAAI,qBAAqB,OAAO,MAAM,CAAC,IAAI,EAAE,EAAE,CAAA;AAC5J,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** The EPC header of the SGTIN-96 scheme (Tag Data Standard). */
|
|
2
|
+
export declare const SGTIN_96_HEADER = 48;
|
|
3
|
+
/** The EPC header of the SGTIN-198 scheme (Tag Data Standard). */
|
|
4
|
+
export declare const SGTIN_198_HEADER = 54;
|
|
5
|
+
/** The file-safe, URI-safe base 64 alphabet of the compression standard §4.1 (RFC 4648 §5). */
|
|
6
|
+
export declare const URI_SAFE_BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
7
|
+
/**
|
|
8
|
+
* The SGTIN partition table of the Tag Data Standard: for each partition
|
|
9
|
+
* value, the bits and digits of the GS1 Company Prefix and of the item
|
|
10
|
+
* reference (indicator digit included). The two digit counts always sum to
|
|
11
|
+
* thirteen, so the GTIN-14 is the indicator digit, the company prefix, the
|
|
12
|
+
* rest of the item reference and a check digit.
|
|
13
|
+
*/
|
|
14
|
+
export declare const SGTIN_PARTITIONS: ReadonlyArray<{
|
|
15
|
+
companyPrefixBits: number;
|
|
16
|
+
companyPrefixDigits: number;
|
|
17
|
+
itemReferenceBits: number;
|
|
18
|
+
itemReferenceDigits: number;
|
|
19
|
+
}>;
|
|
20
|
+
/** The GS1 AI encodable character set 82, which the SGTIN-198 serial and every Digital Link qualifier value draw from. */
|
|
21
|
+
export declare const GS1_CHARACTER_SET_82: RegExp;
|
|
22
|
+
export interface SgtinDecoding {
|
|
23
|
+
ok: true;
|
|
24
|
+
scheme: 'sgtin-96' | 'sgtin-198';
|
|
25
|
+
/** The eight-bit EPC header, as read. */
|
|
26
|
+
header: number;
|
|
27
|
+
/** The three-bit filter value, preserved and not interpreted. */
|
|
28
|
+
filter: number;
|
|
29
|
+
partition: number;
|
|
30
|
+
companyPrefix: string;
|
|
31
|
+
/** The item reference with its indicator digit first, at the partition's digit count. */
|
|
32
|
+
itemReference: string;
|
|
33
|
+
/** The GTIN at fourteen digits, check digit computed. */
|
|
34
|
+
gtin: string;
|
|
35
|
+
serial: string;
|
|
36
|
+
/** The pure-identity EPC URI of the Tag Data Standard, with the serial percent-escaped as that standard requires. */
|
|
37
|
+
epcUri: string;
|
|
38
|
+
}
|
|
39
|
+
export type EpcBinaryRefusalReason = 'empty' | 'not-hex' | 'not-uri-safe-base64' | 'unsupported-epc-scheme' | 'length' | 'partition' | 'company-prefix' | 'item-reference' | 'serial';
|
|
40
|
+
export interface EpcBinaryRefusal {
|
|
41
|
+
ok: false;
|
|
42
|
+
reason: EpcBinaryRefusalReason;
|
|
43
|
+
detail: string;
|
|
44
|
+
/** The header as two hex digits, when the string was long enough to read one. */
|
|
45
|
+
header?: string;
|
|
46
|
+
}
|
|
47
|
+
export type EpcBinaryDecoding = SgtinDecoding | EpcBinaryRefusal;
|
|
48
|
+
/** A string of `0` and `1` from lower-case hexadecimal, four bits per character (compression standard §4.2.1). */
|
|
49
|
+
export declare function bitsFromHex(hex: string): string | undefined;
|
|
50
|
+
/** A string of `0` and `1` from the URI-safe base 64 alphabet, six bits per character (compression standard §4.1). */
|
|
51
|
+
export declare function bitsFromUriSafeBase64(text: string): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Decode an EPC binary string, given as bits, under the SGTIN-96 and SGTIN-198
|
|
54
|
+
* schemes. The bit count must be exactly the scheme's length; a hexadecimal
|
|
55
|
+
* encoding of a 198-bit string carries two padding bits, which must be zero.
|
|
56
|
+
*/
|
|
57
|
+
export declare function decodeEpcBinaryBits(bits: string): EpcBinaryDecoding;
|
|
58
|
+
/**
|
|
59
|
+
* Decode the compression string of a special compressed GS1 Digital Link URI:
|
|
60
|
+
* the two characters after the slash select the alphabet (`eh` hexadecimal,
|
|
61
|
+
* `ex` URI-safe base 64) and the rest is the EPC binary string.
|
|
62
|
+
*/
|
|
63
|
+
export declare function decodeEpcCompressionString(compressionString: string): EpcBinaryDecoding;
|
|
64
|
+
/**
|
|
65
|
+
* The inverse, for tests and for a writer that prints a compressed carrier:
|
|
66
|
+
* an SGTIN-96 or SGTIN-198 EPC binary string as bits, from its parts. Refuses
|
|
67
|
+
* a serial the scheme cannot carry rather than truncating it.
|
|
68
|
+
*/
|
|
69
|
+
export declare function encodeSgtinBits(input: {
|
|
70
|
+
scheme: 'sgtin-96' | 'sgtin-198';
|
|
71
|
+
filter: number;
|
|
72
|
+
partition: number;
|
|
73
|
+
companyPrefix: string;
|
|
74
|
+
itemReference: string;
|
|
75
|
+
serial: string;
|
|
76
|
+
}): string;
|
|
77
|
+
/** Bits to the `eh` form: lower-case hexadecimal, zero-padded to a multiple of four bits. */
|
|
78
|
+
export declare function hexFromBits(bits: string): string;
|
|
79
|
+
/** Bits to the `ex` form: the URI-safe base 64 alphabet, zero-padded to a multiple of six bits. */
|
|
80
|
+
export declare function uriSafeBase64FromBits(bits: string): string;
|
|
81
|
+
//# sourceMappingURL=gs1-epc-binary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gs1-epc-binary.d.ts","sourceRoot":"","sources":["../src/gs1-epc-binary.ts"],"names":[],"mappings":"AAoBA,iEAAiE;AACjE,eAAO,MAAM,eAAe,KAAO,CAAA;AACnC,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,KAAO,CAAA;AAEpC,+FAA+F;AAC/F,eAAO,MAAM,wBAAwB,qEAAqE,CAAA;AAE1G;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,EAAE,aAAa,CAAC;IAAE,iBAAiB,EAAE,MAAM,CAAC;IA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