@cratis/fundamentals 7.18.2 → 7.18.4
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/README.md +26 -2
- package/dist/cjs/ConceptAs.js.map +1 -1
- package/dist/cjs/DateOnly.js.map +1 -1
- package/dist/cjs/DerivedType.js.map +1 -1
- package/dist/cjs/Field.js.map +1 -1
- package/dist/cjs/Fields.js.map +1 -1
- package/dist/cjs/Guid.js.map +1 -1
- package/dist/cjs/JsonSerializer.js.map +1 -1
- package/dist/cjs/PropertyAccessorDescriptor.js.map +1 -1
- package/dist/cjs/PropertyPathResolverProxyHandler.js.map +1 -1
- package/dist/cjs/TimeOnly.js.map +1 -1
- package/dist/cjs/TimeSpan.js.map +1 -1
- package/dist/cjs/ValueMap.js.map +1 -1
- package/dist/cjs/_virtual/_tslib.js.map +1 -1
- package/dist/cjs/derivedTypeDecorator.js.map +1 -1
- package/dist/cjs/duplicateInstanceGuard.js.map +1 -1
- package/dist/cjs/fieldDecorator.js.map +1 -1
- package/dist/cjs/fieldDecoratorMetadata.js.map +1 -1
- package/dist/cjs/geospatial/LineString.js.map +1 -1
- package/dist/cjs/geospatial/LinearRing.js.map +1 -1
- package/dist/cjs/geospatial/Point.js.map +1 -1
- package/dist/cjs/geospatial/Polygon.js.map +1 -1
- package/dist/cjs/json/DateJsonConverter.js.map +1 -1
- package/dist/cjs/json/DateOnlyJsonConverter.js.map +1 -1
- package/dist/cjs/json/GuidJsonConverter.js.map +1 -1
- package/dist/cjs/json/JsonConverter.js.map +1 -1
- package/dist/cjs/json/LineStringJsonConverter.js.map +1 -1
- package/dist/cjs/json/PointJsonConverter.js.map +1 -1
- package/dist/cjs/json/PolygonJsonConverter.js.map +1 -1
- package/dist/cjs/json/TimeOnlyJsonConverter.js.map +1 -1
- package/dist/cjs/json/TimeSpanJsonConverter.js.map +1 -1
- package/dist/cjs/json/ValueMapJsonConverter.js.map +1 -1
- package/dist/cjs/reflection.js.map +1 -1
- package/dist/cjs/typeKey.js.map +1 -1
- package/dist/esm/ConceptAs.js.map +1 -1
- package/dist/esm/DateOnly.js.map +1 -1
- package/dist/esm/DerivedType.js.map +1 -1
- package/dist/esm/Field.js.map +1 -1
- package/dist/esm/Fields.js.map +1 -1
- package/dist/esm/Guid.js.map +1 -1
- package/dist/esm/JsonSerializer.js.map +1 -1
- package/dist/esm/PropertyAccessorDescriptor.js.map +1 -1
- package/dist/esm/PropertyPathResolverProxyHandler.js.map +1 -1
- package/dist/esm/TimeOnly.js.map +1 -1
- package/dist/esm/TimeSpan.js.map +1 -1
- package/dist/esm/ValueMap.js.map +1 -1
- package/dist/esm/_virtual/_tslib.js.map +1 -1
- package/dist/esm/derivedTypeDecorator.js.map +1 -1
- package/dist/esm/duplicateInstanceGuard.js.map +1 -1
- package/dist/esm/fieldDecorator.js.map +1 -1
- package/dist/esm/fieldDecoratorMetadata.js.map +1 -1
- package/dist/esm/geospatial/LineString.js.map +1 -1
- package/dist/esm/geospatial/LinearRing.js.map +1 -1
- package/dist/esm/geospatial/Point.js.map +1 -1
- package/dist/esm/geospatial/Polygon.js.map +1 -1
- package/dist/esm/json/DateJsonConverter.js.map +1 -1
- package/dist/esm/json/DateOnlyJsonConverter.js.map +1 -1
- package/dist/esm/json/GuidJsonConverter.js.map +1 -1
- package/dist/esm/json/JsonConverter.js.map +1 -1
- package/dist/esm/json/LineStringJsonConverter.js.map +1 -1
- package/dist/esm/json/PointJsonConverter.js.map +1 -1
- package/dist/esm/json/PolygonJsonConverter.js.map +1 -1
- package/dist/esm/json/TimeOnlyJsonConverter.js.map +1 -1
- package/dist/esm/json/TimeSpanJsonConverter.js.map +1 -1
- package/dist/esm/json/ValueMapJsonConverter.js.map +1 -1
- package/dist/esm/typeKey.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -3
- package/dist/vite.config.d.mts +0 -3
- package/dist/vite.config.d.mts.map +0 -1
- package/dist/vite.config.mjs +0 -5
- package/dist/vite.config.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
# Fundamentals
|
|
2
2
|
|
|
3
|
+
The shared building blocks beneath the Cratis stack — concepts, serialization, dependency injection, and type discovery for .NET and TypeScript.
|
|
4
|
+
|
|
3
5
|
## Packages
|
|
4
6
|
|
|
5
7
|
[](http://nuget.org/packages/cratis.fundamentals)
|
|
6
8
|
[](https://www.npmjs.com/package/@cratis/fundamentals)
|
|
9
|
+
[](./LICENSE)
|
|
7
10
|
|
|
8
11
|
## Builds
|
|
9
12
|
|
|
10
13
|
[](https://github.com/cratis/Fundamentals/actions/workflows/dotnet-build.yml)
|
|
11
14
|
[](https://github.com/cratis/Fundamentals/actions/workflows/javascript-build.yml)
|
|
12
|
-
[](https://github.com/Cratis/Documentation/actions/workflows/docs-site.yml)
|
|
13
16
|
|
|
14
17
|
## Description
|
|
15
18
|
|
|
@@ -19,7 +22,9 @@ building blocks.
|
|
|
19
22
|
|
|
20
23
|
You should look at it as a convenience layer on top of the existing base environment you're running in.
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
Fundamentals underpins the rest of the Cratis stack: [Chronicle](https://github.com/Cratis/Chronicle) (the event-sourcing database and runtime), [Arc](https://github.com/Cratis/Arc) (the CQRS application framework for ASP.NET Core), and [Components](https://github.com/Cratis/Components) (the React component library) all build on it — and you can use it on its own.
|
|
26
|
+
|
|
27
|
+
Read more about how to use it in the [Fundamentals documentation](https://www.cratis.io/fundamentals/).
|
|
23
28
|
|
|
24
29
|
## Support
|
|
25
30
|
|
|
@@ -76,3 +81,22 @@ In a package, all you need to do is to define the scripts to use the global scri
|
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
```
|
|
84
|
+
|
|
85
|
+
## The Cratis ecosystem
|
|
86
|
+
|
|
87
|
+
This project is part of [Cratis](https://www.cratis.io) — free, MIT-licensed tools for building event-sourced and CQRS applications.
|
|
88
|
+
|
|
89
|
+
- **[Chronicle](https://github.com/Cratis/Chronicle)** — event-sourcing database and runtime. Orleans-based kernel, pluggable storage (MongoDB default; PostgreSQL, SQL Server, SQLite, in-memory), language-agnostic gRPC contracts. [Docs](https://www.cratis.io/chronicle/)
|
|
90
|
+
- **Chronicle clients** — first-class [.NET SDK](https://github.com/Cratis/Chronicle), plus [TypeScript](https://github.com/Cratis/Chronicle.TypeScript), [Kotlin/Java](https://github.com/Cratis/Chronicle.Kotlin), and [Elixir](https://github.com/Cratis/Chronicle.Elixir); [Python](https://github.com/Cratis/Chronicle.Python) coming soon (pre-alpha). AI agents connect through the [Chronicle MCP server](https://github.com/Cratis/Chronicle.Mcp).
|
|
91
|
+
- **[Arc](https://github.com/Cratis/Arc)** — opinionated CQRS framework for ASP.NET Core with commands, queries, validation, authorization, and TypeScript proxy generation. Works without event sourcing. [Docs](https://www.cratis.io/arc/)
|
|
92
|
+
- **[Components](https://github.com/Cratis/Components)** — React components aligned with Arc patterns. [Docs](https://www.cratis.io/components/)
|
|
93
|
+
- **[CLI](https://github.com/Cratis/cli) + Workbench** — inspect and diagnose Chronicle from the terminal or the browser. [Docs](https://www.cratis.io/cli/)
|
|
94
|
+
- **Model-first layer (experimental)** — Studio, [Screenplay](https://github.com/Cratis/Screenplay), [Stage](https://github.com/Cratis/Stage), [Scene](https://github.com/Cratis/Scene), [Prologue](https://github.com/Cratis/Prologue)
|
|
95
|
+
- **Supporting** — [Fundamentals](https://github.com/Cratis/Fundamentals), [Specifications](https://github.com/Cratis/Specifications), [Synopsis](https://github.com/Cratis/Synopsis), [Lens](https://github.com/Cratis/Lens), [Narrator](https://github.com/Cratis/Narrator), and free [AI tooling](https://github.com/Cratis/AI) (preview); Ensemble coming soon (pre-release)
|
|
96
|
+
- **[Samples](https://github.com/Cratis/Samples)** — runnable event sourcing and CQRS samples for the whole stack
|
|
97
|
+
|
|
98
|
+
Everything Cratis publishes today is MIT licensed and free to use.
|
|
99
|
+
|
|
100
|
+
Join the community on [Discord](https://discord.gg/kt4AMpV8WV).
|
|
101
|
+
|
|
102
|
+
Release notes and announcements: the [Cratis blog](https://blog.cratis.io).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConceptAs.js","sources":["../../ConceptAs.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\nimport { typeKey } from './typeKey';\n\n/**\n * Expresses a Concept as another type, usually a primitive such as string or number.\n * @template T The type of the underlying value.\n */\nexport abstract class ConceptAs<T> {\n static readonly [typeKey] = 'ConceptAs';\n\n /**\n * Initializes a new instance of ConceptAs.\n * @param {T} value The value to initialize the concept with.\n */\n constructor(readonly value: T) {}\n\n /**\n * Returns the primitive value of the concept.\n * @returns {T} The underlying value.\n */\n valueOf(): T {\n return this.value;\n }\n\n /**\n * Returns the string representation of the concept.\n * @returns {string} String representation of the underlying value.\n */\n toString(): string {\n return String(this.value);\n }\n}\n"],"names":["typeKey"],"mappings":";;;;MAQsB,SAAS,CAAA;AAON,IAAA,KAAA;AANrB,IAAA,QAAiBA,eAAO,IAAI,WAAW;AAMvC,IAAA,WAAA,CAAqB,KAAQ,EAAA;QAAR,IAAA,CAAA,KAAK,GAAL,KAAK;IAAM;IAMhC,OAAO,GAAA;QACH,OAAO,IAAI,CAAC,KAAK;IACrB;IAMA,QAAQ,GAAA;AACJ,QAAA,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;IAC7B
|
|
1
|
+
{"version":3,"file":"ConceptAs.js","sources":["../../ConceptAs.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\nimport { typeKey } from './typeKey';\n\n/**\n * Expresses a Concept as another type, usually a primitive such as string or number.\n * @template T The type of the underlying value.\n */\nexport abstract class ConceptAs<T> {\n static readonly [typeKey] = 'ConceptAs';\n\n /**\n * Initializes a new instance of ConceptAs.\n * @param {T} value The value to initialize the concept with.\n */\n constructor(readonly value: T) {}\n\n /**\n * Returns the primitive value of the concept.\n * @returns {T} The underlying value.\n */\n valueOf(): T {\n return this.value;\n }\n\n /**\n * Returns the string representation of the concept.\n * @returns {string} String representation of the underlying value.\n */\n toString(): string {\n return String(this.value);\n }\n}\n"],"names":["typeKey"],"mappings":";;;;MAQsB,SAAS,CAAA;AAON,IAAA,KAAA;AANrB,IAAA,QAAiBA,eAAO,IAAI,WAAW;AAMvC,IAAA,WAAA,CAAqB,KAAQ,EAAA;QAAR,IAAA,CAAA,KAAK,GAAL,KAAK;IAAM;IAMhC,OAAO,GAAA;QACH,OAAO,IAAI,CAAC,KAAK;IACrB;IAMA,QAAQ,GAAA;AACJ,QAAA,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;IAC7B;;;"}
|
package/dist/cjs/DateOnly.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateOnly.js","sources":["../../DateOnly.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { field } from './fieldDecorator';\nimport { typeKey } from './typeKey';\n\nconst dateOnlyRegex = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\n\n/**\n * Represents a date with no time and no time zone - a day on a calendar.\n * @remarks\n * Deliberately not a JavaScript `Date`. A `Date` is an instant, and a calendar date is not one: turning\n * `2026-05-12` into a `Date` produces UTC midnight, which every browser-local getter west of UTC reads back as\n * the 11th. That is a wrong answer that looks right, and it is only wrong for users in some time zones - which is\n * how it survives development in others.\n *\n * Holding the three parts the server sent means there is no instant to convert and nothing to shift. Where a\n * `Date` is genuinely wanted - to feed a date picker, or to do arithmetic - {@link toDate} constructs one in the\n * local time zone, and the choice is then visible at the call site making it.\n */\nexport class DateOnly {\n static readonly [typeKey] = 'DateOnly';\n\n /**\n * The year.\n */\n @field(Number)\n year!: number;\n\n /**\n * The month, 1 through 12.\n */\n @field(Number)\n month!: number;\n\n /**\n * The day of the month, 1 through 31.\n */\n @field(Number)\n day!: number;\n\n /**\n * Creates a {@link DateOnly} from its parts.\n * @param year The year.\n * @param month The month, 1 through 12.\n * @param day The day of the month.\n * @returns The {@link DateOnly}.\n */\n static from(year: number, month: number, day: number): DateOnly {\n const dateOnly = new DateOnly();\n dateOnly.year = year;\n dateOnly.month = month;\n dateOnly.day = day;\n return dateOnly;\n }\n\n /**\n * Parses the ISO-8601 calendar date the server sends, `yyyy-MM-dd`.\n * @param value The value to parse.\n * @returns The {@link DateOnly}.\n */\n static parse(value: string): DateOnly {\n const match = dateOnlyRegex.exec(value);\n if (match === null) {\n throw new Error(`Invalid DateOnly format: ${value}`);\n }\n\n return DateOnly.from(parseInt(match[1], 10), parseInt(match[2], 10), parseInt(match[3], 10));\n }\n\n /**\n * Creates a {@link DateOnly} for the calendar date a {@link Date} falls on in the local time zone.\n * @param date The date to take the calendar date of.\n * @returns The {@link DateOnly}.\n * @remarks\n * Reads the local parts rather than the UTC ones, because the calendar date a moment falls on is a question\n * only a time zone can answer, and the local one is the one the person looking at the screen is in.\n */\n static fromDate(date: Date): DateOnly {\n return DateOnly.from(date.getFullYear(), date.getMonth() + 1, date.getDate());\n }\n\n /**\n * Converts to a {@link Date} at midnight in the local time zone.\n * @returns The {@link Date}.\n * @remarks\n * Local rather than UTC, so the date a caller reads back with `getDate()` is the one they started with. This\n * invents a time that was never sent, which is why it is a method to call rather than what the value is.\n */\n toDate(): Date {\n return new Date(this.year, this.month - 1, this.day);\n }\n\n /**\n * Gets the ISO-8601 representation, `yyyy-MM-dd` - the same form the server sent.\n * @returns The string.\n */\n toString(): string {\n const month = this.month.toString().padStart(2, '0');\n const day = this.day.toString().padStart(2, '0');\n return `${this.year.toString().padStart(4, '0')}-${month}-${day}`;\n }\n\n /**\n * Determines whether this is the same calendar date as another.\n * @param other The other date.\n * @returns True when they are the same date.\n */\n equals(other: DateOnly | undefined | null): boolean {\n return !!other && this.year === other.year && this.month === other.month && this.day === other.day;\n }\n}\n"],"names":["typeKey","__decorate","field"],"mappings":";;;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MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;AACpD,QAAA,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;AAChD,QAAA,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA,EAAI,GAAG,EAAE;IACrE;AAOA,IAAA,MAAM,CAAC,KAAkC,EAAA;QACrC,OAAO,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG;IACtG;;AAnFAC,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACA,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAMdD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACC,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAMfD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACD,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,KAAA,EAAA,MAAA,CAAA
|
|
1
|
+
{"version":3,"file":"DateOnly.js","sources":["../../DateOnly.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { field } from './fieldDecorator';\nimport { typeKey } from './typeKey';\n\nconst dateOnlyRegex = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\n\n/**\n * Represents a date with no time and no time zone - a day on a calendar.\n * @remarks\n * Deliberately not a JavaScript `Date`. A `Date` is an instant, and a calendar date is not one: turning\n * `2026-05-12` into a `Date` produces UTC midnight, which every browser-local getter west of UTC reads back as\n * the 11th. That is a wrong answer that looks right, and it is only wrong for users in some time zones - which is\n * how it survives development in others.\n *\n * Holding the three parts the server sent means there is no instant to convert and nothing to shift. Where a\n * `Date` is genuinely wanted - to feed a date picker, or to do arithmetic - {@link toDate} constructs one in the\n * local time zone, and the choice is then visible at the call site making it.\n */\nexport class DateOnly {\n static readonly [typeKey] = 'DateOnly';\n\n /**\n * The year.\n */\n @field(Number)\n year!: number;\n\n /**\n * The month, 1 through 12.\n */\n @field(Number)\n month!: number;\n\n /**\n * The day of the month, 1 through 31.\n */\n @field(Number)\n day!: number;\n\n /**\n * Creates a {@link DateOnly} from its parts.\n * @param year The year.\n * @param month The month, 1 through 12.\n * @param day The day of the month.\n * @returns The {@link DateOnly}.\n */\n static from(year: number, month: number, day: number): DateOnly {\n const dateOnly = new DateOnly();\n dateOnly.year = year;\n dateOnly.month = month;\n dateOnly.day = day;\n return dateOnly;\n }\n\n /**\n * Parses the ISO-8601 calendar date the server sends, `yyyy-MM-dd`.\n * @param value The value to parse.\n * @returns The {@link DateOnly}.\n */\n static parse(value: string): DateOnly {\n const match = dateOnlyRegex.exec(value);\n if (match === null) {\n throw new Error(`Invalid DateOnly format: ${value}`);\n }\n\n return DateOnly.from(parseInt(match[1], 10), parseInt(match[2], 10), parseInt(match[3], 10));\n }\n\n /**\n * Creates a {@link DateOnly} for the calendar date a {@link Date} falls on in the local time zone.\n * @param date The date to take the calendar date of.\n * @returns The {@link DateOnly}.\n * @remarks\n * Reads the local parts rather than the UTC ones, because the calendar date a moment falls on is a question\n * only a time zone can answer, and the local one is the one the person looking at the screen is in.\n */\n static fromDate(date: Date): DateOnly {\n return DateOnly.from(date.getFullYear(), date.getMonth() + 1, date.getDate());\n }\n\n /**\n * Converts to a {@link Date} at midnight in the local time zone.\n * @returns The {@link Date}.\n * @remarks\n * Local rather than UTC, so the date a caller reads back with `getDate()` is the one they started with. This\n * invents a time that was never sent, which is why it is a method to call rather than what the value is.\n */\n toDate(): Date {\n return new Date(this.year, this.month - 1, this.day);\n }\n\n /**\n * Gets the ISO-8601 representation, `yyyy-MM-dd` - the same form the server sent.\n * @returns The string.\n */\n toString(): string {\n const month = this.month.toString().padStart(2, '0');\n const day = this.day.toString().padStart(2, '0');\n return `${this.year.toString().padStart(4, '0')}-${month}-${day}`;\n }\n\n /**\n * Determines whether this is the same calendar date as another.\n * @param other The other date.\n * @returns True when they are the same date.\n */\n equals(other: DateOnly | undefined | null): boolean {\n return !!other && this.year === other.year && this.month === other.month && this.day === other.day;\n }\n}\n"],"names":["typeKey","__decorate","field"],"mappings":";;;;;;AAMA,MAAM,aAAa,GAAG,2BAA2B;MAcpC,QAAQ,CAAA;AACjB,IAAA,QAAiBA,eAAO,IAAI,UAAU;AAMtC,IAAA,IAAI;AAMJ,IAAA,KAAK;AAML,IAAA,GAAG;AASH,IAAA,OAAO,IAAI,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW,EAAA;AAChD,QAAA,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE;AAC/B,QAAA,QAAQ,CAAC,IAAI,GAAG,IAAI;AACpB,QAAA,QAAQ,CAAC,KAAK,GAAG,KAAK;AACtB,QAAA,QAAQ,CAAC,GAAG,GAAG,GAAG;AAClB,QAAA,OAAO,QAAQ;IACnB;IAOA,OAAO,KAAK,CAAC,KAAa,EAAA;QACtB,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC;AACvC,QAAA,IAAI,KAAK,KAAK,IAAI,EAAE;AAChB,YAAA,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAA,CAAE,CAAC;QACxD;AAEA,QAAA,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAA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,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAMfD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACD,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,KAAA,EAAA,MAAA,CAAA;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DerivedType.js","sources":["../../DerivedType.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport './reflection';\nimport { Constructor } from './Constructor';\n\nexport class DerivedType {\n static set(target: Constructor, identifier: string, targetType?: Constructor) {\n Reflect.defineMetadata('derivedType', identifier, target);\n if (targetType) {\n const existing: Constructor[] = Reflect.getOwnMetadata('derivedTypes', targetType) ?? [];\n if (!existing.includes(target)) {\n existing.push(target);\n Reflect.defineMetadata('derivedTypes', existing, targetType);\n }\n }\n }\n\n static get(target: Constructor): string {\n return Reflect.getOwnMetadata('derivedType', target);\n }\n\n static getDerivedTypesFor(targetType: Constructor): Constructor[] {\n return Reflect.getOwnMetadata('derivedTypes', targetType) ?? [];\n }\n}\n"],"names":[],"mappings":";;;;MAMa,WAAW,CAAA;AACpB,IAAA,OAAO,GAAG,CAAC,MAAmB,EAAE,UAAkB,EAAE,UAAwB,EAAA;QACxE,OAAO,CAAC,cAAc,CAAC,aAAa,EAAE,UAAU,EAAE,MAAM,CAAC;QACzD,IAAI,UAAU,EAAE;AACZ,YAAA,MAAM,QAAQ,GAAkB,OAAO,CAAC,cAAc,CAAC,cAAc,EAAE,UAAU,CAAC,IAAI,EAAE;YACxF,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;AAC5B,gBAAA,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;gBACrB,OAAO,CAAC,cAAc,CAAC,cAAc,EAAE,QAAQ,EAAE,UAAU,CAAC;YAChE;QACJ;IACJ;IAEA,OAAO,GAAG,CAAC,MAAmB,EAAA;QAC1B,OAAO,OAAO,CAAC,cAAc,CAAC,aAAa,EAAE,MAAM,CAAC;IACxD;IAEA,OAAO,kBAAkB,CAAC,UAAuB,EAAA;QAC7C,OAAO,OAAO,CAAC,cAAc,CAAC,cAAc,EAAE,UAAU,CAAC,IAAI,EAAE;IACnE;AACH
|
|
1
|
+
{"version":3,"file":"DerivedType.js","sources":["../../DerivedType.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport './reflection';\nimport { Constructor } from './Constructor';\n\nexport class DerivedType {\n static set(target: Constructor, identifier: string, targetType?: Constructor) {\n Reflect.defineMetadata('derivedType', identifier, target);\n if (targetType) {\n const existing: Constructor[] = Reflect.getOwnMetadata('derivedTypes', targetType) ?? [];\n if (!existing.includes(target)) {\n existing.push(target);\n Reflect.defineMetadata('derivedTypes', existing, targetType);\n }\n }\n }\n\n static get(target: Constructor): string {\n return Reflect.getOwnMetadata('derivedType', target);\n }\n\n static getDerivedTypesFor(targetType: Constructor): Constructor[] {\n return Reflect.getOwnMetadata('derivedTypes', targetType) ?? [];\n }\n}\n"],"names":[],"mappings":";;;;MAMa,WAAW,CAAA;AACpB,IAAA,OAAO,GAAG,CAAC,MAAmB,EAAE,UAAkB,EAAE,UAAwB,EAAA;QACxE,OAAO,CAAC,cAAc,CAAC,aAAa,EAAE,UAAU,EAAE,MAAM,CAAC;QACzD,IAAI,UAAU,EAAE;AACZ,YAAA,MAAM,QAAQ,GAAkB,OAAO,CAAC,cAAc,CAAC,cAAc,EAAE,UAAU,CAAC,IAAI,EAAE;YACxF,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;AAC5B,gBAAA,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;gBACrB,OAAO,CAAC,cAAc,CAAC,cAAc,EAAE,QAAQ,EAAE,UAAU,CAAC;YAChE;QACJ;IACJ;IAEA,OAAO,GAAG,CAAC,MAAmB,EAAA;QAC1B,OAAO,OAAO,CAAC,cAAc,CAAC,aAAa,EAAE,MAAM,CAAC;IACxD;IAEA,OAAO,kBAAkB,CAAC,UAAuB,EAAA;QAC7C,OAAO,OAAO,CAAC,cAAc,CAAC,cAAc,EAAE,UAAU,CAAC,IAAI,EAAE;IACnE;AACH;;"}
|
package/dist/cjs/Field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.js","sources":["../../Field.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from './Constructor';\n\n/**\n * Represents a field on a type.\n */\n export class Field {\n constructor(\n readonly name: string,\n readonly type: Constructor,\n readonly enumerable: boolean,\n readonly derivatives: Constructor[],\n readonly genericArguments: Constructor[]) {\n }\n}\n"],"names":[],"mappings":";;MAQc,KAAK,CAAA;AAEF,IAAA,IAAA;AACA,IAAA,IAAA;AACA,IAAA,UAAA;AACA,IAAA,WAAA;AACA,IAAA,gBAAA;IALb,WAAA,CACa,IAAY,EACZ,IAAiB,EACjB,UAAmB,EACnB,WAA0B,EAC1B,gBAA+B,EAAA;QAJ/B,IAAA,CAAA,IAAI,GAAJ,IAAI;QACJ,IAAA,CAAA,IAAI,GAAJ,IAAI;QACJ,IAAA,CAAA,UAAU,GAAV,UAAU;QACV,IAAA,CAAA,WAAW,GAAX,WAAW;QACX,IAAA,CAAA,gBAAgB,GAAhB,gBAAgB;IAC7B;AACH
|
|
1
|
+
{"version":3,"file":"Field.js","sources":["../../Field.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from './Constructor';\n\n/**\n * Represents a field on a type.\n */\n export class Field {\n constructor(\n readonly name: string,\n readonly type: Constructor,\n readonly enumerable: boolean,\n readonly derivatives: Constructor[],\n readonly genericArguments: Constructor[]) {\n }\n}\n"],"names":[],"mappings":";;MAQc,KAAK,CAAA;AAEF,IAAA,IAAA;AACA,IAAA,IAAA;AACA,IAAA,UAAA;AACA,IAAA,WAAA;AACA,IAAA,gBAAA;IALb,WAAA,CACa,IAAY,EACZ,IAAiB,EACjB,UAAmB,EACnB,WAA0B,EAC1B,gBAA+B,EAAA;QAJ/B,IAAA,CAAA,IAAI,GAAJ,IAAI;QACJ,IAAA,CAAA,IAAI,GAAJ,IAAI;QACJ,IAAA,CAAA,UAAU,GAAV,UAAU;QACV,IAAA,CAAA,WAAW,GAAX,WAAW;QACX,IAAA,CAAA,gBAAgB,GAAhB,gBAAgB;IAC7B;AACH;;"}
|
package/dist/cjs/Fields.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Fields.js","sources":["../../Fields.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport './reflection';\nimport { Constructor } from './Constructor';\nimport { Field } from './Field';\nimport { getOwnDecoratorFieldsForType } from './fieldDecoratorMetadata';\n\n/**\n * Represents a system working with fields on types.\n */\nexport class Fields {\n static addFieldToType(target: Constructor, field: string, fieldType: Constructor, enumerable: boolean, derivatives: Constructor[], genericArguments: Constructor[]) {\n let fields: Map<string, Field> = new Map<string, Field>();\n if (Reflect.hasOwnMetadata('fields', target)) {\n fields = Reflect.getOwnMetadata('fields', target);\n }\n fields.set(field, new Field(field, fieldType, enumerable, derivatives, genericArguments));\n Reflect.defineMetadata('fields', fields, target);\n }\n\n static getFieldsForType(target: Constructor): Field[] {\n // Fields are stored as legacy own metadata on the constructor or as standard own metadata on\n // its Symbol.metadata object, so a derived type only carries the fields it declares itself.\n // Walk the prototype (inheritance) chain and merge every ancestor's fields so that deserializing\n // a derived type also populates the fields inherited from its base types.\n // Process from the base type down to the target so a derived field overrides a base field of the\n // same name.\n const chain: Constructor[] = [];\n let current: Constructor | undefined = target;\n while (current && current !== Function.prototype && current !== Object) {\n chain.push(current);\n current = Object.getPrototypeOf(current) as Constructor | undefined;\n }\n\n const fieldsByName = new Map<string, Field>();\n for (let index = chain.length - 1; index >= 0; index--) {\n const type = chain[index];\n if (Reflect.hasOwnMetadata('fields', type)) {\n const fieldsMap = Reflect.getOwnMetadata('fields', type) as Map<string, Field>;\n for (const [name, field] of fieldsMap.entries()) {\n fieldsByName.set(name, field);\n }\n }\n\n for (const field of getOwnDecoratorFieldsForType(type)) {\n fieldsByName.set(field.name, field);\n }\n }\n\n return [...fieldsByName.values()];\n }\n}\n"],"names":["Field","getOwnDecoratorFieldsForType"],"mappings":";;;;;;MAWa,MAAM,CAAA;AACf,IAAA,OAAO,cAAc,CAAC,MAAmB,EAAE,KAAa,EAAE,SAAsB,EAAE,UAAmB,EAAE,WAA0B,EAAE,gBAA+B,EAAA;AAC9J,QAAA,IAAI,MAAM,GAAuB,IAAI,GAAG,EAAiB;QACzD,IAAI,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE;YAC1C,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC;QACrD;AACA,QAAA,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAIA,WAAK,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC;QACzF,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;IACpD;IAEA,OAAO,gBAAgB,CAAC,MAAmB,EAAA;QAOvC,MAAM,KAAK,GAAkB,EAAE;QAC/B,IAAI,OAAO,GAA4B,MAAM;AAC7C,QAAA,OAAO,OAAO,IAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,IAAI,OAAO,KAAK,MAAM,EAAE;AACpE,YAAA,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;AACnB,YAAA,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAA4B;QACvE;AAEA,QAAA,MAAM,YAAY,GAAG,IAAI,GAAG,EAAiB;AAC7C,QAAA,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE;AACpD,YAAA,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC;YACzB,IAAI,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE;gBACxC,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAuB;AAC9E,gBAAA,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE;AAC7C,oBAAA,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC;gBACjC;YACJ;YAEA,KAAK,MAAM,KAAK,IAAIC,mDAA4B,CAAC,IAAI,CAAC,EAAE;gBACpD,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;YACvC;QACJ;AAEA,QAAA,OAAO,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC;IACrC;AACH
|
|
1
|
+
{"version":3,"file":"Fields.js","sources":["../../Fields.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport './reflection';\nimport { Constructor } from './Constructor';\nimport { Field } from './Field';\nimport { getOwnDecoratorFieldsForType } from './fieldDecoratorMetadata';\n\n/**\n * Represents a system working with fields on types.\n */\nexport class Fields {\n static addFieldToType(target: Constructor, field: string, fieldType: Constructor, enumerable: boolean, derivatives: Constructor[], genericArguments: Constructor[]) {\n let fields: Map<string, Field> = new Map<string, Field>();\n if (Reflect.hasOwnMetadata('fields', target)) {\n fields = Reflect.getOwnMetadata('fields', target);\n }\n fields.set(field, new Field(field, fieldType, enumerable, derivatives, genericArguments));\n Reflect.defineMetadata('fields', fields, target);\n }\n\n static getFieldsForType(target: Constructor): Field[] {\n // Fields are stored as legacy own metadata on the constructor or as standard own metadata on\n // its Symbol.metadata object, so a derived type only carries the fields it declares itself.\n // Walk the prototype (inheritance) chain and merge every ancestor's fields so that deserializing\n // a derived type also populates the fields inherited from its base types.\n // Process from the base type down to the target so a derived field overrides a base field of the\n // same name.\n const chain: Constructor[] = [];\n let current: Constructor | undefined = target;\n while (current && current !== Function.prototype && current !== Object) {\n chain.push(current);\n current = Object.getPrototypeOf(current) as Constructor | undefined;\n }\n\n const fieldsByName = new Map<string, Field>();\n for (let index = chain.length - 1; index >= 0; index--) {\n const type = chain[index];\n if (Reflect.hasOwnMetadata('fields', type)) {\n const fieldsMap = Reflect.getOwnMetadata('fields', type) as Map<string, Field>;\n for (const [name, field] of fieldsMap.entries()) {\n fieldsByName.set(name, field);\n }\n }\n\n for (const field of getOwnDecoratorFieldsForType(type)) {\n fieldsByName.set(field.name, field);\n }\n }\n\n return [...fieldsByName.values()];\n }\n}\n"],"names":["Field","getOwnDecoratorFieldsForType"],"mappings":";;;;;;MAWa,MAAM,CAAA;AACf,IAAA,OAAO,cAAc,CAAC,MAAmB,EAAE,KAAa,EAAE,SAAsB,EAAE,UAAmB,EAAE,WAA0B,EAAE,gBAA+B,EAAA;AAC9J,QAAA,IAAI,MAAM,GAAuB,IAAI,GAAG,EAAiB;QACzD,IAAI,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE;YAC1C,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC;QACrD;AACA,QAAA,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAIA,WAAK,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC;QACzF,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;IACpD;IAEA,OAAO,gBAAgB,CAAC,MAAmB,EAAA;QAOvC,MAAM,KAAK,GAAkB,EAAE;QAC/B,IAAI,OAAO,GAA4B,MAAM;AAC7C,QAAA,OAAO,OAAO,IAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,IAAI,OAAO,KAAK,MAAM,EAAE;AACpE,YAAA,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;AACnB,YAAA,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAA4B;QACvE;AAEA,QAAA,MAAM,YAAY,GAAG,IAAI,GAAG,EAAiB;AAC7C,QAAA,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE;AACpD,YAAA,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC;YACzB,IAAI,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE;gBACxC,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAuB;AAC9E,gBAAA,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE;AAC7C,oBAAA,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC;gBACjC;YACJ;YAEA,KAAK,MAAM,KAAK,IAAIC,mDAA4B,CAAC,IAAI,CAAC,EAAE;gBACpD,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;YACvC;QACJ;AAEA,QAAA,OAAO,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC;IACrC;AACH;;"}
|
package/dist/cjs/Guid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Guid.js","sources":["../../Guid.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { IEquatable } from './IEquatable';\nimport { typeKey } from './typeKey';\n\nconst guidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;\nconst lookUpTable: string[] = [];\n(() => {\n for (let i = 0; i < 256; i += 1) {\n lookUpTable[i] = (i < 16 ? '0' : '') + (i).toString(16);\n }\n})();\n\nconst getString = (num: number) => {\n return num.toString(16).padStart(2, '0');\n};\n\n/**\n * Represents a Guid according to the http://www.ietf.org/rfc/rfc4122.txt\n *\n * @export\n * @class Guid\n */\nexport class Guid implements IEquatable {\n static readonly [typeKey] = 'Guid';\n\n\n /**\n * Gets an empty {Guid}\n */\n static readonly empty = new Guid([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);\n\n private _stringVersion = '';\n\n\n /**\n * Initializes a new instance of the {Guid} class.\n * @param {number[]|Uint8Array} bytes - The 16 bytes that represents a {Guid}.\n */\n constructor(readonly bytes: number[] | Uint8Array | undefined) {\n if( bytes === undefined ) {\n this._stringVersion = Guid.empty.toString();\n return;\n }\n\n this._stringVersion = '' +\n getString(bytes[3]) + getString(bytes[2]) + getString(bytes[1]) + getString(bytes[0]) +\n '-' +\n getString(bytes[5]) + getString(bytes[4]) +\n '-' +\n getString(bytes[7]) + getString(bytes[6]) +\n '-' +\n getString(bytes[8]) + getString(bytes[9]) +\n '-' +\n getString(bytes[10]) + getString(bytes[11]) + getString(bytes[12]) + getString(bytes[13]) + getString(bytes[14]) + getString(bytes[15]);\n }\n\n /**\n * Create a new {Guid}\n * @returns {Guid}\n */\n static create(): Guid {\n const d0 = Math.random() * 0xFFFFFFFF | 0;\n const d1 = Math.random() * 0xFFFFFFFF | 0;\n const d2 = Math.random() * 0xFFFFFFFF | 0;\n const d3 = Math.random() * 0xFFFFFFFF | 0;\n\n const bytes = [\n lookUpTable[d0 & 0xFF],\n lookUpTable[d0 >> 8 & 0xFF],\n lookUpTable[d0 >> 16 & 0xFF],\n lookUpTable[d0 >> 24 & 0xFF],\n lookUpTable[d1 & 0xFF],\n lookUpTable[d1 >> 8 & 0xFF],\n lookUpTable[d1 >> 16 & 0x0F | 0x40],\n lookUpTable[d1 >> 24 & 0xFF],\n lookUpTable[d2 & 0x3F | 0x80],\n lookUpTable[d2 >> 8 & 0xFF],\n lookUpTable[d2 >> 16 & 0xFF],\n lookUpTable[d2 >> 24 & 0xFF],\n lookUpTable[d3 & 0xFF],\n lookUpTable[d3 >> 8 & 0xFF],\n lookUpTable[d3 >> 16 & 0xFF],\n lookUpTable[d3 >> 24 & 0xFF]\n ];\n\n return new Guid(bytes.map(_ => parseInt(`0x${_}`, 16)));\n }\n\n /**\n * Parses a string and turns it into a {Guid}.\n * @param {string} guid String representation of guid.\n */\n static parse(guid: string): Guid {\n const bytes: number[] = [];\n guid.split('-').map((number, index) => {\n const bytesInChar = index < 3 ? number.match(/.{1,2}/g)?.reverse() : number.match(/.{1,2}/g);\n bytesInChar?.map((byte) => { bytes.push(parseInt(byte, 16)); });\n });\n\n return new Guid(bytes);\n }\n\n /**\n * Check if a string is a valid {Guid}\n * @param {string} value Value to check.\n * @returns True if it is, false if not.\n */\n static isGuid(value: string): boolean {\n return guidRegex.test(value);\n }\n\n /**\n * Parses if the type is a string parse, otherwise pass through the input as desired output type.\n * @template T Type to handle for\n * @param {string|T} input String or the generic type.\n * @returns identifier Parsed or passed through\n */\n static as<T extends Guid = Guid>(input: string | T): T {\n if (typeof input === 'string') {\n return Guid.parse(input) as T;\n }\n return input as T;\n }\n\n /**\n * @inheritdoc\n */\n equals(other: object): boolean {\n const actualOther = other instanceof Guid ? other : other.toString();\n if (typeof actualOther === 'string' && !Guid.isGuid(actualOther)) {\n return false;\n }\n\n return Guid.as(actualOther).toString() === this.toString();\n }\n\n /**\n * Return a string representation of the {Guid} in the format: 00000000-0000-0000-0000-000000000000\n * @returns {string}\n */\n toString(): string {\n return this._stringVersion;\n }\n\n /**\n * Converts the {Guid} to a string that works in JSON serialization.\n * @returns {string}\n */\n toJSON(): string {\n return this._stringVersion;\n }\n}\n"],"names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C5F,WAAW,EAAE,GAAG,CAAC,CAAC,IAAI,KAAI,EAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnE,QAAA,CAAC,CAAC;AAEF,QAAA,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC;IAC1B;IAOA,OAAO,MAAM,CAAC,KAAa,EAAA;AACvB,QAAA,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;IAChC;IAQA,OAAO,EAAE,CAAwB,KAAiB,EAAA;AAC9C,QAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC3B,YAAA,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAM;QACjC;AACA,QAAA,OAAO,KAAU;IACrB;AAKA,IAAA,MAAM,CAAC,KAAa,EAAA;AAChB,QAAA,MAAM,WAAW,GAAG,KAAK,YAAY,IAAI,GAAG,KAAK,GAAG,KAAK,CAAC,QAAQ,EAAE;AACpE,QAAA,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE;AAC9D,YAAA,OAAO,KAAK;QAChB;AAEA,QAAA,OAAO,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,QAAQ,EAAE;IAC9D;IAMA,QAAQ,GAAA;QACJ,OAAO,IAAI,CAAC,cAAc;IAC9B;IAMA,MAAM,GAAA;QACF,OAAO,IAAI,CAAC,cAAc;IAC9B
|
|
1
|
+
{"version":3,"file":"Guid.js","sources":["../../Guid.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { IEquatable } from './IEquatable';\nimport { typeKey } from './typeKey';\n\nconst guidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;\nconst lookUpTable: string[] = [];\n(() => {\n for (let i = 0; i < 256; i += 1) {\n lookUpTable[i] = (i < 16 ? '0' : '') + (i).toString(16);\n }\n})();\n\nconst getString = (num: number) => {\n return num.toString(16).padStart(2, '0');\n};\n\n/**\n * Represents a Guid according to the http://www.ietf.org/rfc/rfc4122.txt\n *\n * @export\n * @class Guid\n */\nexport class Guid implements IEquatable {\n static readonly [typeKey] = 'Guid';\n\n\n /**\n * Gets an empty {Guid}\n */\n static readonly empty = new Guid([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);\n\n private _stringVersion = '';\n\n\n /**\n * Initializes a new instance of the {Guid} class.\n * @param {number[]|Uint8Array} bytes - The 16 bytes that represents a {Guid}.\n */\n constructor(readonly bytes: number[] | Uint8Array | undefined) {\n if( bytes === undefined ) {\n this._stringVersion = Guid.empty.toString();\n return;\n }\n\n this._stringVersion = '' +\n getString(bytes[3]) + getString(bytes[2]) + getString(bytes[1]) + getString(bytes[0]) +\n '-' +\n getString(bytes[5]) + getString(bytes[4]) +\n '-' +\n getString(bytes[7]) + getString(bytes[6]) +\n '-' +\n getString(bytes[8]) + getString(bytes[9]) +\n '-' +\n getString(bytes[10]) + getString(bytes[11]) + getString(bytes[12]) + getString(bytes[13]) + getString(bytes[14]) + getString(bytes[15]);\n }\n\n /**\n * Create a new {Guid}\n * @returns {Guid}\n */\n static create(): Guid {\n const d0 = Math.random() * 0xFFFFFFFF | 0;\n const d1 = Math.random() * 0xFFFFFFFF | 0;\n const d2 = Math.random() * 0xFFFFFFFF | 0;\n const d3 = Math.random() * 0xFFFFFFFF | 0;\n\n const bytes = [\n lookUpTable[d0 & 0xFF],\n lookUpTable[d0 >> 8 & 0xFF],\n lookUpTable[d0 >> 16 & 0xFF],\n lookUpTable[d0 >> 24 & 0xFF],\n lookUpTable[d1 & 0xFF],\n lookUpTable[d1 >> 8 & 0xFF],\n lookUpTable[d1 >> 16 & 0x0F | 0x40],\n lookUpTable[d1 >> 24 & 0xFF],\n lookUpTable[d2 & 0x3F | 0x80],\n lookUpTable[d2 >> 8 & 0xFF],\n lookUpTable[d2 >> 16 & 0xFF],\n lookUpTable[d2 >> 24 & 0xFF],\n lookUpTable[d3 & 0xFF],\n lookUpTable[d3 >> 8 & 0xFF],\n lookUpTable[d3 >> 16 & 0xFF],\n lookUpTable[d3 >> 24 & 0xFF]\n ];\n\n return new Guid(bytes.map(_ => parseInt(`0x${_}`, 16)));\n }\n\n /**\n * Parses a string and turns it into a {Guid}.\n * @param {string} guid String representation of guid.\n */\n static parse(guid: string): Guid {\n const bytes: number[] = [];\n guid.split('-').map((number, index) => {\n const bytesInChar = index < 3 ? number.match(/.{1,2}/g)?.reverse() : number.match(/.{1,2}/g);\n bytesInChar?.map((byte) => { bytes.push(parseInt(byte, 16)); });\n });\n\n return new Guid(bytes);\n }\n\n /**\n * Check if a string is a valid {Guid}\n * @param {string} value Value to check.\n * @returns True if it is, false if not.\n */\n static isGuid(value: string): boolean {\n return guidRegex.test(value);\n }\n\n /**\n * Parses if the type is a string parse, otherwise pass through the input as desired output type.\n * @template T Type to handle for\n * @param {string|T} input String or the generic type.\n * @returns identifier Parsed or passed through\n */\n static as<T extends Guid = Guid>(input: string | T): T {\n if (typeof input === 'string') {\n return Guid.parse(input) as T;\n }\n return input as T;\n }\n\n /**\n * @inheritdoc\n */\n equals(other: object): boolean {\n const actualOther = other instanceof Guid ? other : other.toString();\n if (typeof actualOther === 'string' && !Guid.isGuid(actualOther)) {\n return false;\n }\n\n return Guid.as(actualOther).toString() === this.toString();\n }\n\n /**\n * Return a string representation of the {Guid} in the format: 00000000-0000-0000-0000-000000000000\n * @returns {string}\n */\n toString(): string {\n return this._stringVersion;\n }\n\n /**\n * Converts the {Guid} to a string that works in JSON serialization.\n * @returns {string}\n */\n toJSON(): string {\n return this._stringVersion;\n }\n}\n"],"names":["typeKey"],"mappings":";;;;AAMA,MAAM,SAAS,GAAG,+EAA+E;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KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnE,QAAA,CAAC,CAAC;AAEF,QAAA,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC;IAC1B;IAOA,OAAO,MAAM,CAAC,KAAa,EAAA;AACvB,QAAA,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;IAChC;IAQA,OAAO,EAAE,CAAwB,KAAiB,EAAA;AAC9C,QAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC3B,YAAA,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAM;QACjC;AACA,QAAA,OAAO,KAAU;IACrB;AAKA,IAAA,MAAM,CAAC,KAAa,EAAA;AAChB,QAAA,MAAM,WAAW,GAAG,KAAK,YAAY,IAAI,GAAG,KAAK,GAAG,KAAK,CAAC,QAAQ,EAAE;AACpE,QAAA,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE;AAC9D,YAAA,OAAO,KAAK;QAChB;AAEA,QAAA,OAAO,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,QAAQ,EAAE;IAC9D;IAMA,QAAQ,GAAA;QACJ,OAAO,IAAI,CAAC,cAAc;IAC9B;IAMA,MAAM,GAAA;QACF,OAAO,IAAI,CAAC,cAAc;IAC9B;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonSerializer.js","sources":["../../JsonSerializer.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from './Constructor';\nimport { DerivedType } from './DerivedType';\nimport { registerModuleInstance } from './duplicateInstanceGuard';\nimport { Field } from './Field';\nimport { Fields } from './Fields';\nimport { conceptAsTypeKey, declaredTypeKey, typeKeyOf, valueMapTypeKey } from './typeKey';\nimport { ValueMap } from './ValueMap';\nimport { \n JsonConverter, \n DateJsonConverter, \n DateOnlyJsonConverter,\n GuidJsonConverter, \n TimeOnlyJsonConverter,\n TimeSpanJsonConverter, \n PointJsonConverter,\n LineStringJsonConverter,\n PolygonJsonConverter,\n ValueMapJsonConverter\n} from './json';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\ntype typeSerializer = (value: any) => any;\n\n// A second copy of this package in the same realm builds its own registry here, and brings its own\n// class objects. Convertible values still cross between the copies, because a type is recognized by\n// the key it declares - but a converter registered on one copy reaches only that one, and a version\n// pinned at the top level never reaches a nested copy. Announce it where the state that cannot be\n// shared is built.\nregisterModuleInstance();\n\n// Initialize converters\nconst converters: JsonConverter[] = [\n new DateJsonConverter(),\n new DateOnlyJsonConverter(),\n new GuidJsonConverter(),\n new TimeOnlyJsonConverter(),\n new TimeSpanJsonConverter(),\n new PointJsonConverter(),\n new LineStringJsonConverter(),\n new PolygonJsonConverter(),\n new ValueMapJsonConverter()\n];\n\n// Converters are found by the key a type declares, and only by the constructor when it declares none.\n// Keying on the constructor alone is what made a second copy of this package silently fatal: each copy\n// brings its own Guid, ConceptAs and ValueMap class objects, so neither recognized the other's. A key\n// crosses that boundary; a class object does not. A consumer's own type has no key and is found by\n// constructor, which is exact and needs nothing to cross.\nconst keyedConverters: Map<string, JsonConverter> = new Map<string, JsonConverter>();\nconst typeConverters: Map<Constructor, JsonConverter> = new Map<Constructor, JsonConverter>();\n\nconst registerConverterFor = (converter: JsonConverter) => {\n const key = declaredTypeKey(converter.type);\n if (key !== undefined) {\n keyedConverters.set(key, converter);\n }\n\n typeConverters.set(converter.type, converter);\n};\n\nconverters.forEach(registerConverterFor);\n\n/**\n * Finds the converter registered for a type, if any.\n * @param {Constructor} type The type to convert.\n * @returns {JsonConverter | undefined} The converter, or undefined when the type has none.\n */\nconst converterFor = (type: Constructor | undefined): JsonConverter | undefined => {\n if (!type) return undefined;\n\n const key = declaredTypeKey(type);\n const keyed = key === undefined ? undefined : keyedConverters.get(key);\n return keyed ?? typeConverters.get(type);\n};\n\n/**\n * Checks whether a type is a ValueMap, including one from another copy of this package.\n * @param {Constructor} type The type to check.\n * @returns {boolean} True when the type is a ValueMap.\n */\nconst isValueMap = (type: Constructor | undefined): boolean => declaredTypeKey(type) === valueMapTypeKey;\n\n// Add primitive type converters that don't need a full JsonConverter class\nconst primitiveConverters: Map<Constructor, typeSerializer> = new Map<Constructor, typeSerializer>([\n [Number, (value: number) => value],\n [String, (value: string) => value],\n [Boolean, (value: boolean) => value]\n]);\n\nconst primitiveSerializers: Map<Constructor, typeSerializer> = new Map<Constructor, typeSerializer>([\n [Number, (value: any) => value],\n [String, (value: any) => value],\n [Boolean, (value: any) => value]\n]);\n\n/**\n * Checks if a constructor is a ConceptAs type.\n * @param {Constructor} type The constructor to check.\n * @returns {boolean} True if the type extends ConceptAs.\n * @remarks\n * Reads the key rather than walking the prototype chain looking for this copy's ConceptAs. The key is a\n * static and a static is inherited, so every type deriving from ConceptAs carries it - including one\n * deriving from another copy's ConceptAs, which a prototype walk could never recognize.\n */\nconst isConceptAs = (type: Constructor): boolean => typeKeyOf(type) === conceptAsTypeKey;\n\nconst serializeValueForType = (type: Constructor, value: any) => {\n if (!value) return value;\n\n // If it's a ConceptAs instance, unwrap it and serialize the inner value recursively\n // This follows the C# pattern: recognize as concept, unwrap, then call serializer\n if (isConceptAs(value.constructor)) {\n const innerValue = value.value;\n // Recursively serialize the inner value to handle complex types\n // Use .constructor directly which works reliably for both primitives and objects\n return serializeValueForType(innerValue.constructor, innerValue);\n }\n\n // Check if there's a registered converter\n const converter = converterFor(type);\n if (converter) {\n return converter.write(value);\n }\n \n // Check primitive converters\n if (primitiveConverters.has(type)) {\n return primitiveConverters.get(type)!(value);\n }\n \n return convertTypesOnInstance(value);\n};\n\nconst deserializeValueFromType = (type: Constructor, value: any) => {\n // If it's a ConceptAs type, instantiate it with the value\n if (isConceptAs(type)) {\n return new type(value);\n }\n \n // Check if there's a registered converter\n const converter = converterFor(type);\n if (converter) {\n return converter.read(value);\n }\n \n // Check primitive serializers\n if (primitiveSerializers.has(type)) {\n return primitiveSerializers.get(type)!(value);\n }\n \n return JsonSerializer.deserialize(type, JSON.stringify(value));\n};\n\nconst deserializeValueFromField = (field: Field, value: any) => {\n if (isValueMap(field.type)) {\n return deserializeValueMapFromField(field, value);\n }\n\n // If it's a ConceptAs type, instantiate it with the value\n if (isConceptAs(field.type)) {\n return new field.type(value);\n }\n\n // Check if there's a registered converter\n const converter = converterFor(field.type);\n if (converter) {\n return converter.read(value);\n }\n \n // Check primitive serializers\n if (primitiveSerializers.has(field.type)) {\n return primitiveSerializers.get(field.type)!(value);\n }\n \n let type = field.type;\n if (value[JsonSerializer.DerivedTypeIdProperty]) {\n const derivedTypeId = value[JsonSerializer.DerivedTypeIdProperty];\n const candidates = [...field.derivatives, ...DerivedType.getDerivedTypesFor(field.type)];\n type = candidates.find(_ => DerivedType.get(_) == derivedTypeId) || type;\n }\n\n return JsonSerializer.deserialize(type, JSON.stringify(value));\n};\n\nconst serializeMapKey = (key: any): string => {\n if (key === undefined || key === null) {\n return '';\n }\n\n if (typeof key === 'string') {\n return key;\n }\n\n if (typeof key === 'number' || typeof key === 'boolean' || typeof key === 'bigint') {\n return key.toString();\n }\n\n if (key instanceof Date) {\n return key.toISOString();\n }\n\n return JsonSerializer.serialize(key);\n};\n\nconst deserializeMapKey = (keyType: Constructor, key: string): any => {\n if (keyType === String) {\n return key;\n }\n\n if (keyType === Number) {\n return Number(key);\n }\n\n if (keyType === Boolean) {\n return key.toLowerCase() === 'true';\n }\n\n // Check if there's a converter for this type\n const converter = converterFor(keyType);\n if (converter) {\n return converter.read(key);\n }\n\n return JsonSerializer.deserialize(keyType, key);\n};\n\nconst deserializeMapValue = (valueType: Constructor | undefined, value: any): any => {\n if (!valueType) {\n return value;\n }\n\n // A map value is an ordinary value of its declared type, so read it the way any other value of that\n // type is read. Resolving it here instead left out the concept and primitive cases, and the\n // primitive one lost data without a sound: a string value went through JsonSerializer.deserialize,\n // which built an empty String object because a primitive has no fields to populate.\n return deserializeValueFromType(valueType, value);\n};\n\nconst deserializeValueMapFromField = (field: Field, value: any): ValueMap<any, any> => {\n const valueMap = new ValueMap<any, any>();\n const keyType = field.genericArguments[0];\n const valueType = field.genericArguments[1];\n\n if (!value || !keyType) {\n return valueMap;\n }\n\n for (const key of Object.keys(value)) {\n const deserializedKey = deserializeMapKey(keyType, key);\n const deserializedValue = deserializeMapValue(valueType, value[key]);\n valueMap.set(deserializedKey, deserializedValue);\n }\n\n return valueMap;\n};\n\nconst convertTypesOnInstance = (instance: any) => {\n // A concept unwraps to its underlying value wherever it is reached, not only when it is reached\n // through a declared field. An array element and a map value arrive here rather than at\n // serializeValueForType, and without this they were written as the object a concept happens to be -\n // {\"value\": ...} where the receiver declared the underlying type.\n if (isConceptAs(instance.constructor)) {\n return serializeValueForType(instance.constructor as Constructor, instance);\n }\n\n // Check if there's a converter for this type\n if (converterFor(instance.constructor)) {\n return serializeValueForType(instance.constructor, instance);\n }\n \n // Check primitive converters\n if (primitiveConverters.has(instance.constructor)) {\n return primitiveConverters.get(instance.constructor)!(instance);\n }\n\n const properties = Object.getOwnPropertyNames(instance);\n const converted: any = {};\n\n // Emit the polymorphic type discriminator, preferring the registered type for the instance's\n // constructor and falling back to a discriminator preserved on the instance itself (e.g. a value\n // that was deserialized before its concrete type could be resolved). This keeps '_derivedTypeId'\n // flowing through serialization transparently — the caller never has to manage it — and is the\n // mirror of preserving it on deserialization.\n const derivedTypeId = DerivedType.get(instance.constructor) ?? instance[JsonSerializer.DerivedTypeIdProperty];\n if (derivedTypeId) {\n converted[JsonSerializer.DerivedTypeIdProperty] = derivedTypeId;\n }\n properties.forEach(property => {\n // The discriminator is handled above as a meta-property; never treat it as a data field.\n if (property === JsonSerializer.DerivedTypeIdProperty) return;\n let value = instance[property];\n if (value !== undefined) {\n if (Array.isArray(value)) {\n value = value.map(_ => convertTypesOnInstance(_));\n } else {\n value = serializeValueForType(value.__proto__.constructor, value);\n }\n }\n\n converted[property] = value;\n });\n\n return converted;\n};\n\n// Initialize ValueMapJsonConverter with helper functions to avoid circular dependencies\n// Must be done after serializeMapKey and convertTypesOnInstance are defined\nValueMapJsonConverter.setHelpers(serializeMapKey, convertTypesOnInstance);\n\n/**\n * Represents a serializer for JSON.\n */\nexport class JsonSerializer {\n static readonly DerivedTypeIdProperty: string = \"_derivedTypeId\";\n\n /**\n * Register a converter for the type it declares through its `type` property.\n * @param {JsonConverter} converter The converter to register.\n * @remarks\n * The converter is used for both directions - `read` on the way in, `write` on the way out - and\n * takes the place of any converter already registered for the same type, including the built-in\n * ones. Replacing a built-in changes the payloads the application produces and consumes, which is\n * the caller's to decide; nothing here second-guesses it.\n *\n * Two shapes resolve ahead of the converters, so a converter registered for them is not reached:\n *\n * - A type deriving from `ConceptAs` is unwrapped to its underlying value in both directions, and\n * converted as that value's type. Register for the underlying type to reach a concept.\n * - A `ValueMap` is read back from the declaring field's generic arguments rather than through a\n * converter. Note the asymmetry: writing a `ValueMap` *does* go through the registered converter,\n * so replacing that one changes only the outbound half.\n */\n static registerConverter(converter: JsonConverter): void {\n registerConverterFor(converter);\n }\n\n /**\n * Serialize with strong type information.\n * @param {*} value The value to serialize.\n * @returns A JSON string.\n */\n static serialize(value: any): string {\n const converted = convertTypesOnInstance(value);\n return JSON.stringify(converted);\n }\n\n /**\n * Deserialize a JSON string to the specific type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {string} json Actual JSON to deserialize.\n * @returns An instance of the target type.\n */\n static deserialize<TResult extends object>(targetType: Constructor<TResult>, json: string): TResult {\n const parsed = JSON.parse(json);\n return this.deserializeFromInstance<TResult>(targetType, parsed);\n }\n\n /**\n * Deserialize a array JSON string to an array of the specific instance type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {string} json Actual JSON to deserialize.\n * @returns An array of instances of the target type.\n */\n static deserializeArray<TResult extends object>(targetType: Constructor<TResult>, json: string): TResult[] {\n const parsed = JSON.parse(json);\n return this.deserializeArrayFromInstance(targetType, parsed);\n }\n\n /**\n * Deserialize an any instance to a specific instance type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {*} instance Actual instance to deserialize.\n * @returns An instance of the target type.\n */\n static deserializeFromInstance<TResult extends object>(targetType: Constructor<TResult>, instance: any): TResult {\n const fields = Fields.getFieldsForType(targetType as Constructor);\n\n if (converterFor(targetType)) {\n return deserializeValueFromType(targetType, instance);\n }\n\n const deserialized = new targetType();\n for (const field of fields) {\n let value = instance[field.name];\n if (value) {\n if (field.enumerable) {\n value = value.map(_ => deserializeValueFromField(field, _));\n } else {\n value = deserializeValueFromField(field, value);\n }\n } else if (field.enumerable && value === undefined) {\n // A collection that is absent from the payload deserializes to an empty one rather than to\n // undefined. The declared type says the field is an array, and a producer that leaves an\n // empty collection out - which the Chronicle sink does deliberately, so that a parallel\n // replay cannot overwrite children a sibling event already wrote - would otherwise hand back\n // a value contradicting its own type, putting a null guard on every reader of every\n // collection. An explicit null is left alone: that is the producer saying \"no collection\"\n // rather than \"an empty one\".\n value = [];\n }\n\n deserialized[field.name] = value;\n }\n\n // Preserve the polymorphic type discriminator so it is never lost across (de)serialization\n // layers. '_derivedTypeId' is not a declared field, so it is otherwise dropped here — and a\n // derived value whose concrete type could not be resolved (e.g. its type was not yet\n // registered) would then have no discriminator left to re-resolve or round-trip with, and\n // would serialize back with no type information at all.\n const derivedTypeId = instance[JsonSerializer.DerivedTypeIdProperty];\n if (derivedTypeId !== undefined && derivedTypeId !== null) {\n (deserialized as Record<string, unknown>)[JsonSerializer.DerivedTypeIdProperty] = derivedTypeId;\n }\n\n if ((targetType as Constructor) == Object) {\n const objectFields = Object.keys(instance).filter((value) => {\n return !fields.some(_ => _.name == value);\n });\n\n for (const field of objectFields) {\n deserialized[field] = instance[field];\n }\n }\n\n return deserialized;\n }\n\n /**\n * Deserialize an array of any instances to an array of specific instance types.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {instances} instances Actual instances to deserialize.\n * @returns An array of instances of the target type.\n */\n static deserializeArrayFromInstance<TResult extends object>(targetType: Constructor<TResult>, instances: any): TResult[] {\n const deserialized: TResult[] = [];\n\n for (const instance of instances) {\n deserialized.push(this.deserializeFromInstance<TResult>(targetType, instance));\n }\n\n return deserialized;\n }\n}\n"],"names":["registerModuleInstance","DateJsonConverter","DateOnlyJsonConverter","GuidJsonConverter","TimeOnlyJsonConverter","TimeSpanJsonConverter","PointJsonConverter","LineStringJsonConverter","PolygonJsonConverter","ValueMapJsonConverter","declaredTypeKey","valueMapTypeKey","typeKeyOf","conceptAsTypeKey","DerivedType","ValueMap","Fields"],"mappings":";;;;;;;;;;;;;;;;;AAgCAA,6CAAsB,EAAE;AAGxB,MAAM,UAAU,GAAoB;AAChC,IAAA,IAAIC,mCAAiB,EAAE;AACvB,IAAA,IAAIC,2CAAqB,EAAE;AAC3B,IAAA,IAAIC,mCAAiB,EAAE;AACvB,IAAA,IAAIC,2CAAqB,EAAE;AAC3B,IAAA,IAAIC,2CAAqB,EAAE;AAC3B,IAAA,IAAIC,qCAAkB,EAAE;AACxB,IAAA,IAAIC,+CAAuB,EAAE;AAC7B,IAAA,IAAIC,yCAAoB,EAAE;AAC1B,IAAA,IAAIC,2CAAqB;CAC5B;AAOD,MAAM,eAAe,GAA+B,IAAI,GAAG,EAAyB;AACpF,MAAM,cAAc,GAAoC,IAAI,GAAG,EAA8B;AAE7F,MAAM,oBAAoB,GAAG,CAAC,SAAwB,KAAI;IACtD,MAAM,GAAG,GAAGC,uBAAe,CAAC,SAAS,CAAC,IAAI,CAAC;AAC3C,IAAA,IAAI,GAAG,KAAK,SAAS,EAAE;AACnB,QAAA,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC;IACvC;IAEA,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC;AACjD,CAAC;AAED,UAAU,CAAC,OAAO,CAAC,oBAAoB,CAAC;AAO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AQ,CAAC,KAAK,CAAC;YACzC;QACJ;AAEA,QAAA,OAAO,YAAY;IACvB;AAQA,IAAA,OAAO,4BAA4B,CAAyB,UAAgC,EAAE,SAAc,EAAA;QACxG,MAAM,YAAY,GAAc,EAAE;AAElC,QAAA,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;AAC9B,YAAA,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAU,UAAU,EAAE,QAAQ,CAAC,CAAC;QAClF;AAEA,QAAA,OAAO,YAAY;IACvB;;;;;"}
|
|
1
|
+
{"version":3,"file":"JsonSerializer.js","sources":["../../JsonSerializer.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from './Constructor';\nimport { DerivedType } from './DerivedType';\nimport { registerModuleInstance } from './duplicateInstanceGuard';\nimport { Field } from './Field';\nimport { Fields } from './Fields';\nimport { conceptAsTypeKey, declaredTypeKey, typeKeyOf, valueMapTypeKey } from './typeKey';\nimport { ValueMap } from './ValueMap';\nimport { \n JsonConverter, \n DateJsonConverter, \n DateOnlyJsonConverter,\n GuidJsonConverter, \n TimeOnlyJsonConverter,\n TimeSpanJsonConverter, \n PointJsonConverter,\n LineStringJsonConverter,\n PolygonJsonConverter,\n ValueMapJsonConverter\n} from './json';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\ntype typeSerializer = (value: any) => any;\n\n// A second copy of this package in the same realm builds its own registry here, and brings its own\n// class objects. Convertible values still cross between the copies, because a type is recognized by\n// the key it declares - but a converter registered on one copy reaches only that one, and a version\n// pinned at the top level never reaches a nested copy. Announce it where the state that cannot be\n// shared is built.\nregisterModuleInstance();\n\n// Initialize converters\nconst converters: JsonConverter[] = [\n new DateJsonConverter(),\n new DateOnlyJsonConverter(),\n new GuidJsonConverter(),\n new TimeOnlyJsonConverter(),\n new TimeSpanJsonConverter(),\n new PointJsonConverter(),\n new LineStringJsonConverter(),\n new PolygonJsonConverter(),\n new ValueMapJsonConverter()\n];\n\n// Converters are found by the key a type declares, and only by the constructor when it declares none.\n// Keying on the constructor alone is what made a second copy of this package silently fatal: each copy\n// brings its own Guid, ConceptAs and ValueMap class objects, so neither recognized the other's. A key\n// crosses that boundary; a class object does not. A consumer's own type has no key and is found by\n// constructor, which is exact and needs nothing to cross.\nconst keyedConverters: Map<string, JsonConverter> = new Map<string, JsonConverter>();\nconst typeConverters: Map<Constructor, JsonConverter> = new Map<Constructor, JsonConverter>();\n\nconst registerConverterFor = (converter: JsonConverter) => {\n const key = declaredTypeKey(converter.type);\n if (key !== undefined) {\n keyedConverters.set(key, converter);\n }\n\n typeConverters.set(converter.type, converter);\n};\n\nconverters.forEach(registerConverterFor);\n\n/**\n * Finds the converter registered for a type, if any.\n * @param {Constructor} type The type to convert.\n * @returns {JsonConverter | undefined} The converter, or undefined when the type has none.\n */\nconst converterFor = (type: Constructor | undefined): JsonConverter | undefined => {\n if (!type) return undefined;\n\n const key = declaredTypeKey(type);\n const keyed = key === undefined ? undefined : keyedConverters.get(key);\n return keyed ?? typeConverters.get(type);\n};\n\n/**\n * Checks whether a type is a ValueMap, including one from another copy of this package.\n * @param {Constructor} type The type to check.\n * @returns {boolean} True when the type is a ValueMap.\n */\nconst isValueMap = (type: Constructor | undefined): boolean => declaredTypeKey(type) === valueMapTypeKey;\n\n// Add primitive type converters that don't need a full JsonConverter class\nconst primitiveConverters: Map<Constructor, typeSerializer> = new Map<Constructor, typeSerializer>([\n [Number, (value: number) => value],\n [String, (value: string) => value],\n [Boolean, (value: boolean) => value]\n]);\n\nconst primitiveSerializers: Map<Constructor, typeSerializer> = new Map<Constructor, typeSerializer>([\n [Number, (value: any) => value],\n [String, (value: any) => value],\n [Boolean, (value: any) => value]\n]);\n\n/**\n * Checks if a constructor is a ConceptAs type.\n * @param {Constructor} type The constructor to check.\n * @returns {boolean} True if the type extends ConceptAs.\n * @remarks\n * Reads the key rather than walking the prototype chain looking for this copy's ConceptAs. The key is a\n * static and a static is inherited, so every type deriving from ConceptAs carries it - including one\n * deriving from another copy's ConceptAs, which a prototype walk could never recognize.\n */\nconst isConceptAs = (type: Constructor): boolean => typeKeyOf(type) === conceptAsTypeKey;\n\nconst serializeValueForType = (type: Constructor, value: any) => {\n if (!value) return value;\n\n // If it's a ConceptAs instance, unwrap it and serialize the inner value recursively\n // This follows the C# pattern: recognize as concept, unwrap, then call serializer\n if (isConceptAs(value.constructor)) {\n const innerValue = value.value;\n // Recursively serialize the inner value to handle complex types\n // Use .constructor directly which works reliably for both primitives and objects\n return serializeValueForType(innerValue.constructor, innerValue);\n }\n\n // Check if there's a registered converter\n const converter = converterFor(type);\n if (converter) {\n return converter.write(value);\n }\n \n // Check primitive converters\n if (primitiveConverters.has(type)) {\n return primitiveConverters.get(type)!(value);\n }\n \n return convertTypesOnInstance(value);\n};\n\nconst deserializeValueFromType = (type: Constructor, value: any) => {\n // If it's a ConceptAs type, instantiate it with the value\n if (isConceptAs(type)) {\n return new type(value);\n }\n \n // Check if there's a registered converter\n const converter = converterFor(type);\n if (converter) {\n return converter.read(value);\n }\n \n // Check primitive serializers\n if (primitiveSerializers.has(type)) {\n return primitiveSerializers.get(type)!(value);\n }\n \n return JsonSerializer.deserialize(type, JSON.stringify(value));\n};\n\nconst deserializeValueFromField = (field: Field, value: any) => {\n if (isValueMap(field.type)) {\n return deserializeValueMapFromField(field, value);\n }\n\n // If it's a ConceptAs type, instantiate it with the value\n if (isConceptAs(field.type)) {\n return new field.type(value);\n }\n\n // Check if there's a registered converter\n const converter = converterFor(field.type);\n if (converter) {\n return converter.read(value);\n }\n \n // Check primitive serializers\n if (primitiveSerializers.has(field.type)) {\n return primitiveSerializers.get(field.type)!(value);\n }\n \n let type = field.type;\n if (value[JsonSerializer.DerivedTypeIdProperty]) {\n const derivedTypeId = value[JsonSerializer.DerivedTypeIdProperty];\n const candidates = [...field.derivatives, ...DerivedType.getDerivedTypesFor(field.type)];\n type = candidates.find(_ => DerivedType.get(_) == derivedTypeId) || type;\n }\n\n return JsonSerializer.deserialize(type, JSON.stringify(value));\n};\n\nconst serializeMapKey = (key: any): string => {\n if (key === undefined || key === null) {\n return '';\n }\n\n if (typeof key === 'string') {\n return key;\n }\n\n if (typeof key === 'number' || typeof key === 'boolean' || typeof key === 'bigint') {\n return key.toString();\n }\n\n if (key instanceof Date) {\n return key.toISOString();\n }\n\n return JsonSerializer.serialize(key);\n};\n\nconst deserializeMapKey = (keyType: Constructor, key: string): any => {\n if (keyType === String) {\n return key;\n }\n\n if (keyType === Number) {\n return Number(key);\n }\n\n if (keyType === Boolean) {\n return key.toLowerCase() === 'true';\n }\n\n // Check if there's a converter for this type\n const converter = converterFor(keyType);\n if (converter) {\n return converter.read(key);\n }\n\n return JsonSerializer.deserialize(keyType, key);\n};\n\nconst deserializeMapValue = (valueType: Constructor | undefined, value: any): any => {\n if (!valueType) {\n return value;\n }\n\n // A map value is an ordinary value of its declared type, so read it the way any other value of that\n // type is read. Resolving it here instead left out the concept and primitive cases, and the\n // primitive one lost data without a sound: a string value went through JsonSerializer.deserialize,\n // which built an empty String object because a primitive has no fields to populate.\n return deserializeValueFromType(valueType, value);\n};\n\nconst deserializeValueMapFromField = (field: Field, value: any): ValueMap<any, any> => {\n const valueMap = new ValueMap<any, any>();\n const keyType = field.genericArguments[0];\n const valueType = field.genericArguments[1];\n\n if (!value || !keyType) {\n return valueMap;\n }\n\n for (const key of Object.keys(value)) {\n const deserializedKey = deserializeMapKey(keyType, key);\n const deserializedValue = deserializeMapValue(valueType, value[key]);\n valueMap.set(deserializedKey, deserializedValue);\n }\n\n return valueMap;\n};\n\nconst convertTypesOnInstance = (instance: any) => {\n // A concept unwraps to its underlying value wherever it is reached, not only when it is reached\n // through a declared field. An array element and a map value arrive here rather than at\n // serializeValueForType, and without this they were written as the object a concept happens to be -\n // {\"value\": ...} where the receiver declared the underlying type.\n if (isConceptAs(instance.constructor)) {\n return serializeValueForType(instance.constructor as Constructor, instance);\n }\n\n // Check if there's a converter for this type\n if (converterFor(instance.constructor)) {\n return serializeValueForType(instance.constructor, instance);\n }\n \n // Check primitive converters\n if (primitiveConverters.has(instance.constructor)) {\n return primitiveConverters.get(instance.constructor)!(instance);\n }\n\n const properties = Object.getOwnPropertyNames(instance);\n const converted: any = {};\n\n // Emit the polymorphic type discriminator, preferring the registered type for the instance's\n // constructor and falling back to a discriminator preserved on the instance itself (e.g. a value\n // that was deserialized before its concrete type could be resolved). This keeps '_derivedTypeId'\n // flowing through serialization transparently — the caller never has to manage it — and is the\n // mirror of preserving it on deserialization.\n const derivedTypeId = DerivedType.get(instance.constructor) ?? instance[JsonSerializer.DerivedTypeIdProperty];\n if (derivedTypeId) {\n converted[JsonSerializer.DerivedTypeIdProperty] = derivedTypeId;\n }\n properties.forEach(property => {\n // The discriminator is handled above as a meta-property; never treat it as a data field.\n if (property === JsonSerializer.DerivedTypeIdProperty) return;\n let value = instance[property];\n if (value !== undefined) {\n if (Array.isArray(value)) {\n value = value.map(_ => convertTypesOnInstance(_));\n } else {\n value = serializeValueForType(value.__proto__.constructor, value);\n }\n }\n\n converted[property] = value;\n });\n\n return converted;\n};\n\n// Initialize ValueMapJsonConverter with helper functions to avoid circular dependencies\n// Must be done after serializeMapKey and convertTypesOnInstance are defined\nValueMapJsonConverter.setHelpers(serializeMapKey, convertTypesOnInstance);\n\n/**\n * Represents a serializer for JSON.\n */\nexport class JsonSerializer {\n static readonly DerivedTypeIdProperty: string = \"_derivedTypeId\";\n\n /**\n * Register a converter for the type it declares through its `type` property.\n * @param {JsonConverter} converter The converter to register.\n * @remarks\n * The converter is used for both directions - `read` on the way in, `write` on the way out - and\n * takes the place of any converter already registered for the same type, including the built-in\n * ones. Replacing a built-in changes the payloads the application produces and consumes, which is\n * the caller's to decide; nothing here second-guesses it.\n *\n * Two shapes resolve ahead of the converters, so a converter registered for them is not reached:\n *\n * - A type deriving from `ConceptAs` is unwrapped to its underlying value in both directions, and\n * converted as that value's type. Register for the underlying type to reach a concept.\n * - A `ValueMap` is read back from the declaring field's generic arguments rather than through a\n * converter. Note the asymmetry: writing a `ValueMap` *does* go through the registered converter,\n * so replacing that one changes only the outbound half.\n */\n static registerConverter(converter: JsonConverter): void {\n registerConverterFor(converter);\n }\n\n /**\n * Serialize with strong type information.\n * @param {*} value The value to serialize.\n * @returns A JSON string.\n */\n static serialize(value: any): string {\n const converted = convertTypesOnInstance(value);\n return JSON.stringify(converted);\n }\n\n /**\n * Deserialize a JSON string to the specific type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {string} json Actual JSON to deserialize.\n * @returns An instance of the target type.\n */\n static deserialize<TResult extends object>(targetType: Constructor<TResult>, json: string): TResult {\n const parsed = JSON.parse(json);\n return this.deserializeFromInstance<TResult>(targetType, parsed);\n }\n\n /**\n * Deserialize a array JSON string to an array of the specific instance type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {string} json Actual JSON to deserialize.\n * @returns An array of instances of the target type.\n */\n static deserializeArray<TResult extends object>(targetType: Constructor<TResult>, json: string): TResult[] {\n const parsed = JSON.parse(json);\n return this.deserializeArrayFromInstance(targetType, parsed);\n }\n\n /**\n * Deserialize an any instance to a specific instance type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {*} instance Actual instance to deserialize.\n * @returns An instance of the target type.\n */\n static deserializeFromInstance<TResult extends object>(targetType: Constructor<TResult>, instance: any): TResult {\n const fields = Fields.getFieldsForType(targetType as Constructor);\n\n if (converterFor(targetType)) {\n return deserializeValueFromType(targetType, instance);\n }\n\n const deserialized = new targetType();\n for (const field of fields) {\n let value = instance[field.name];\n if (value) {\n if (field.enumerable) {\n value = value.map(_ => deserializeValueFromField(field, _));\n } else {\n value = deserializeValueFromField(field, value);\n }\n } else if (field.enumerable && value === undefined) {\n // A collection that is absent from the payload deserializes to an empty one rather than to\n // undefined. The declared type says the field is an array, and a producer that leaves an\n // empty collection out - which the Chronicle sink does deliberately, so that a parallel\n // replay cannot overwrite children a sibling event already wrote - would otherwise hand back\n // a value contradicting its own type, putting a null guard on every reader of every\n // collection. An explicit null is left alone: that is the producer saying \"no collection\"\n // rather than \"an empty one\".\n value = [];\n }\n\n deserialized[field.name] = value;\n }\n\n // Preserve the polymorphic type discriminator so it is never lost across (de)serialization\n // layers. '_derivedTypeId' is not a declared field, so it is otherwise dropped here — and a\n // derived value whose concrete type could not be resolved (e.g. its type was not yet\n // registered) would then have no discriminator left to re-resolve or round-trip with, and\n // would serialize back with no type information at all.\n const derivedTypeId = instance[JsonSerializer.DerivedTypeIdProperty];\n if (derivedTypeId !== undefined && derivedTypeId !== null) {\n (deserialized as Record<string, unknown>)[JsonSerializer.DerivedTypeIdProperty] = derivedTypeId;\n }\n\n if ((targetType as Constructor) == Object) {\n const objectFields = Object.keys(instance).filter((value) => {\n return !fields.some(_ => _.name == value);\n });\n\n for (const field of objectFields) {\n deserialized[field] = instance[field];\n }\n }\n\n return deserialized;\n }\n\n /**\n * Deserialize an array of any instances to an array of specific instance types.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {instances} instances Actual instances to deserialize.\n * @returns An array of instances of the target type.\n */\n static deserializeArrayFromInstance<TResult extends object>(targetType: Constructor<TResult>, instances: any): TResult[] {\n const deserialized: TResult[] = [];\n\n for (const instance of instances) {\n deserialized.push(this.deserializeFromInstance<TResult>(targetType, instance));\n }\n\n return deserialized;\n }\n}\n"],"names":["registerModuleInstance","DateJsonConverter","DateOnlyJsonConverter","GuidJsonConverter","TimeOnlyJsonConverter","TimeSpanJsonConverter","PointJsonConverter","LineStringJsonConverter","PolygonJsonConverter","ValueMapJsonConverter","declaredTypeKey","valueMapTypeKey","typeKeyOf","conceptAsTypeKey","DerivedType","ValueMap","Fields"],"mappings":";;;;;;;;;;;;;;;;;AAgCAA,6CAAsB,EAAE;AAGxB,MAAM,UAAU,GAAoB;AAChC,IAAA,IAAIC,mCAAiB,EAAE;AACvB,IAAA,IAAIC,2CAAqB,EAAE;AAC3B,IAAA,IAAIC,mCAAiB,EAAE;AACvB,IAAA,IAAIC,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ACd;AAEA,YAAA,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK;QACpC;QAOA,MAAM,aAAa,GAAG,QAAQ,CAAC,cAAc,CAAC,qBAAqB,CAAC;QACpE,IAAI,aAAa,KAAK,SAAS,IAAI,aAAa,KAAK,IAAI,EAAE;AACtD,YAAA,YAAwC,CAAC,cAAc,CAAC,qBAAqB,CAAC,GAAG,aAAa;QACnG;AAEA,QAAA,IAAK,UAA0B,IAAI,MAAM,EAAE;AACvC,YAAA,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,KAAI;AACxD,gBAAA,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC;AAC7C,YAAA,CAAC,CAAC;AAEF,YAAA,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE;gBAC9B,YAAY,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;YACzC;QACJ;AAEA,QAAA,OAAO,YAAY;IACvB;AAQA,IAAA,OAAO,4BAA4B,CAAyB,UAAgC,EAAE,SAAc,EAAA;QACxG,MAAM,YAAY,GAAc,EAAE;AAElC,QAAA,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;AAC9B,YAAA,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAU,UAAU,EAAE,QAAQ,CAAC,CAAC;QAClF;AAEA,QAAA,OAAO,YAAY;IACvB;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyAccessorDescriptor.js","sources":["../../PropertyAccessorDescriptor.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { PropertyAccessor } from './PropertyAccessor';\n\n/**\n * Represents the descriptor of a specific property accessor\n */\nexport class PropertyAccessorDescriptor {\n\n /**\n * Creates an instance of {PropertyAccessorDescriptor}.\n * @param {PropertyAccessor} _accessor - The actual accessor for accessing the property.\n * @param {Array<string>} _segments - The segments representing the path of the property accessor within an instance.\n */\n constructor(private readonly _accessor: PropertyAccessor, private readonly _segments: string[]) {\n }\n\n /**\n * Gets the actual accessor.\n * @returns {PropertyAccessor}\n */\n get accessor(): PropertyAccessor {\n return this._accessor;\n }\n\n /**\n * Gets the segments that constitute the deep path within the object instance for accessing the underlying property.\n * @returns {ReadonlyArray<string>}\n */\n get segments(): readonly string[] {\n return this._segments;\n }\n\n /**\n * Gets the full path to the property\n * @returns {string}\n */\n get path(): string {\n return this._segments.join('.');\n }\n}\n"],"names":[],"mappings":";;MAQa,0BAA0B,CAAA;AAON,IAAA,SAAA;AAA8C,IAAA,SAAA;IAA3E,WAAA,CAA6B,SAA2B,EAAmB,SAAmB,EAAA;QAAjE,IAAA,CAAA,SAAS,GAAT,SAAS;QAAqC,IAAA,CAAA,SAAS,GAAT,SAAS;IACpF;AAMA,IAAA,IAAI,QAAQ,GAAA;QACR,OAAO,IAAI,CAAC,SAAS;IACzB;AAMA,IAAA,IAAI,QAAQ,GAAA;QACR,OAAO,IAAI,CAAC,SAAS;IACzB;AAMA,IAAA,IAAI,IAAI,GAAA;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;IACnC;AACH
|
|
1
|
+
{"version":3,"file":"PropertyAccessorDescriptor.js","sources":["../../PropertyAccessorDescriptor.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { PropertyAccessor } from './PropertyAccessor';\n\n/**\n * Represents the descriptor of a specific property accessor\n */\nexport class PropertyAccessorDescriptor {\n\n /**\n * Creates an instance of {PropertyAccessorDescriptor}.\n * @param {PropertyAccessor} _accessor - The actual accessor for accessing the property.\n * @param {Array<string>} _segments - The segments representing the path of the property accessor within an instance.\n */\n constructor(private readonly _accessor: PropertyAccessor, private readonly _segments: string[]) {\n }\n\n /**\n * Gets the actual accessor.\n * @returns {PropertyAccessor}\n */\n get accessor(): PropertyAccessor {\n return this._accessor;\n }\n\n /**\n * Gets the segments that constitute the deep path within the object instance for accessing the underlying property.\n * @returns {ReadonlyArray<string>}\n */\n get segments(): readonly string[] {\n return this._segments;\n }\n\n /**\n * Gets the full path to the property\n * @returns {string}\n */\n get path(): string {\n return this._segments.join('.');\n }\n}\n"],"names":[],"mappings":";;MAQa,0BAA0B,CAAA;AAON,IAAA,SAAA;AAA8C,IAAA,SAAA;IAA3E,WAAA,CAA6B,SAA2B,EAAmB,SAAmB,EAAA;QAAjE,IAAA,CAAA,SAAS,GAAT,SAAS;QAAqC,IAAA,CAAA,SAAS,GAAT,SAAS;IACpF;AAMA,IAAA,IAAI,QAAQ,GAAA;QACR,OAAO,IAAI,CAAC,SAAS;IACzB;AAMA,IAAA,IAAI,QAAQ,GAAA;QACR,OAAO,IAAI,CAAC,SAAS;IACzB;AAMA,IAAA,IAAI,IAAI,GAAA;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;IACnC;AACH;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyPathResolverProxyHandler.js","sources":["../../PropertyPathResolverProxyHandler.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n\n/**\n * Object proxy handler\n * @template TObject\n */\nexport class PropertyPathResolverProxyHandler implements ProxyHandler<any> {\n _property = '';\n _segments: string[] = [];\n\n constructor(private readonly _root?: PropertyPathResolverProxyHandler) {\n }\n\n get property(): string {\n return this._property;\n }\n\n get segments(): readonly string[] {\n return this._segments;\n }\n\n get path(): string {\n return this._segments.join('.');\n }\n\n private addSegment(segment: string) {\n this._segments.push(segment);\n }\n\n /** @inheritdoc */\n get(target: any, p: PropertyKey, receiver: any): any {\n const root = this._root || this;\n\n const childProperty = new Proxy({}, new PropertyPathResolverProxyHandler(root));\n this._property = p.toString();\n root.addSegment(this._property);\n\n return childProperty;\n }\n}\n"],"names":[],"mappings":";;MAUa,gCAAgC,CAAA;AAIZ,IAAA,KAAA;IAH7B,SAAS,GAAG,EAAE;IACd,SAAS,GAAa,EAAE;AAExB,IAAA,WAAA,CAA6B,KAAwC,EAAA;QAAxC,IAAA,CAAA,KAAK,GAAL,KAAK;IAClC;AAEA,IAAA,IAAI,QAAQ,GAAA;QACR,OAAO,IAAI,CAAC,SAAS;IACzB;AAEA,IAAA,IAAI,QAAQ,GAAA;QACR,OAAO,IAAI,CAAC,SAAS;IACzB;AAEA,IAAA,IAAI,IAAI,GAAA;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;IACnC;AAEQ,IAAA,UAAU,CAAC,OAAe,EAAA;AAC9B,QAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC;IAChC;AAGA,IAAA,GAAG,CAAC,MAAW,EAAE,CAAc,EAAE,QAAa,EAAA;AAC1C,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI;AAE/B,QAAA,MAAM,aAAa,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE,IAAI,gCAAgC,CAAC,IAAI,CAAC,CAAC;AAC/E,QAAA,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,QAAQ,EAAE;AAC7B,QAAA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;AAE/B,QAAA,OAAO,aAAa;IACxB;AACH
|
|
1
|
+
{"version":3,"file":"PropertyPathResolverProxyHandler.js","sources":["../../PropertyPathResolverProxyHandler.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n\n/**\n * Object proxy handler\n * @template TObject\n */\nexport class PropertyPathResolverProxyHandler implements ProxyHandler<any> {\n _property = '';\n _segments: string[] = [];\n\n constructor(private readonly _root?: PropertyPathResolverProxyHandler) {\n }\n\n get property(): string {\n return this._property;\n }\n\n get segments(): readonly string[] {\n return this._segments;\n }\n\n get path(): string {\n return this._segments.join('.');\n }\n\n private addSegment(segment: string) {\n this._segments.push(segment);\n }\n\n /** @inheritdoc */\n get(target: any, p: PropertyKey, receiver: any): any {\n const root = this._root || this;\n\n const childProperty = new Proxy({}, new PropertyPathResolverProxyHandler(root));\n this._property = p.toString();\n root.addSegment(this._property);\n\n return childProperty;\n }\n}\n"],"names":[],"mappings":";;MAUa,gCAAgC,CAAA;AAIZ,IAAA,KAAA;IAH7B,SAAS,GAAG,EAAE;IACd,SAAS,GAAa,EAAE;AAExB,IAAA,WAAA,CAA6B,KAAwC,EAAA;QAAxC,IAAA,CAAA,KAAK,GAAL,KAAK;IAClC;AAEA,IAAA,IAAI,QAAQ,GAAA;QACR,OAAO,IAAI,CAAC,SAAS;IACzB;AAEA,IAAA,IAAI,QAAQ,GAAA;QACR,OAAO,IAAI,CAAC,SAAS;IACzB;AAEA,IAAA,IAAI,IAAI,GAAA;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;IACnC;AAEQ,IAAA,UAAU,CAAC,OAAe,EAAA;AAC9B,QAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC;IAChC;AAGA,IAAA,GAAG,CAAC,MAAW,EAAE,CAAc,EAAE,QAAa,EAAA;AAC1C,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI;AAE/B,QAAA,MAAM,aAAa,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE,IAAI,gCAAgC,CAAC,IAAI,CAAC,CAAC;AAC/E,QAAA,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,QAAQ,EAAE;AAC7B,QAAA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;AAE/B,QAAA,OAAO,aAAa;IACxB;AACH;;"}
|
package/dist/cjs/TimeOnly.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeOnly.js","sources":["../../TimeOnly.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { field } from './fieldDecorator';\nimport { typeKey } from './typeKey';\n\nconst timeOnlyRegex = /^(\\d{2}):(\\d{2})(?::(\\d{2}))?(?:\\.(\\d{1,7}))?$/;\n\n/**\n * Represents a time of day with no date and no time zone.\n * @remarks\n * Deliberately not a JavaScript `Date`. A `Date` needs a date, and a time of day has none: `new Date('14:30:45')`\n * is not an instant pinned to some default day, it is `Invalid Date`. The value is destroyed outright rather than\n * merely shifted, which makes this the starker of the two temporal cases.\n */\nexport class TimeOnly {\n static readonly [typeKey] = 'TimeOnly';\n\n /**\n * The hour, 0 through 23.\n */\n @field(Number)\n hour!: number;\n\n /**\n * The minute, 0 through 59.\n */\n @field(Number)\n minute!: number;\n\n /**\n * The second, 0 through 59.\n */\n @field(Number)\n second!: number;\n\n /**\n * The millisecond, 0 through 999.\n */\n @field(Number)\n millisecond!: number;\n\n /**\n * Creates a {@link TimeOnly} from its parts.\n * @param hour The hour.\n * @param minute The minute.\n * @param second The second.\n * @param millisecond The millisecond.\n * @returns The {@link TimeOnly}.\n */\n static from(hour: number, minute: number, second: number = 0, millisecond: number = 0): TimeOnly {\n const timeOnly = new TimeOnly();\n timeOnly.hour = hour;\n timeOnly.minute = minute;\n timeOnly.second = second;\n timeOnly.millisecond = millisecond;\n return timeOnly;\n }\n\n /**\n * Parses the ISO-8601 time of day the server sends, `HH:mm`, `HH:mm:ss` or `HH:mm:ss.fffffff`.\n * @param value The value to parse.\n * @returns The {@link TimeOnly}.\n * @remarks\n * The seconds and the fraction are both optional because the server omits them when they are zero, and the\n * fraction carries up to seven digits where JavaScript holds three - so it is truncated rather than rounded,\n * which keeps a parse followed by a render from moving the value forward.\n */\n static parse(value: string): TimeOnly {\n const match = timeOnlyRegex.exec(value);\n if (match === null) {\n throw new Error(`Invalid TimeOnly format: ${value}`);\n }\n\n const fraction = match[4] ? match[4].padEnd(3, '0').substring(0, 3) : '0';\n\n return TimeOnly.from(\n parseInt(match[1], 10),\n parseInt(match[2], 10),\n match[3] ? parseInt(match[3], 10) : 0,\n parseInt(fraction, 10));\n }\n\n /**\n * Gets the ISO-8601 representation, `HH:mm:ss` - or `HH:mm:ss.fff` when there is a fractional part.\n * @returns The string.\n */\n toString(): string {\n const hour = this.hour.toString().padStart(2, '0');\n const minute = this.minute.toString().padStart(2, '0');\n const second = this.second.toString().padStart(2, '0');\n const time = `${hour}:${minute}:${second}`;\n return this.millisecond > 0 ? `${time}.${this.millisecond.toString().padStart(3, '0')}` : time;\n }\n\n /**\n * Determines whether this is the same time of day as another.\n * @param other The other time.\n * @returns True when they are the same time.\n */\n equals(other: TimeOnly | undefined | null): boolean {\n return !!other &&\n this.hour === other.hour &&\n this.minute === other.minute &&\n this.second === other.second &&\n this.millisecond === other.millisecond;\n }\n}\n"],"names":["typeKey","__decorate","field"],"mappings":";;;;;;AAMA,MAAM,aAAa,GAAG,gDAAgD;MASzD,QAAQ,CAAA;AACjB,IAAA,QAAiBA,eAAO,IAAI,UAAU;AAMtC,IAAA,IAAI;AAMJ,IAAA,MAAM;AAMN,IAAA,MAAM;AAMN,IAAA,WAAW;IAUX,OAAO,IAAI,CAAC,IAAY,EAAE,MAAc,EAAE,MAAA,GAAiB,CAAC,EAAE,WAAA,GAAsB,CAAC,EAAA;AACjF,QAAA,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE;AAC/B,QAAA,QAAQ,CAAC,IAAI,GAAG,IAAI;AACpB,QAAA,QAAQ,CAAC,MAAM,GAAG,MAAM;AACxB,QAAA,QAAQ,CAAC,MAAM,GAAG,MAA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C1C,QAAA,OAAO,IAAI,CAAC,WAAW,GAAG,CAAC,GAAG,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA,CAAE,GAAG,IAAI;IAClG;AAOA,IAAA,MAAM,CAAC,KAAkC,EAAA;QACrC,OAAO,CAAC,CAAC,KAAK;AACV,YAAA,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;AACxB,YAAA,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;AAC5B,YAAA,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;AAC5B,YAAA,IAAI,CAAC,WAAW,KAAK,KAAK,CAAC,WAAW;IAC9C;;AApFAC,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACA,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAMdD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACE,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAMhBD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACE,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAMhBD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACO,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA
|
|
1
|
+
{"version":3,"file":"TimeOnly.js","sources":["../../TimeOnly.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { field } from './fieldDecorator';\nimport { typeKey } from './typeKey';\n\nconst timeOnlyRegex = /^(\\d{2}):(\\d{2})(?::(\\d{2}))?(?:\\.(\\d{1,7}))?$/;\n\n/**\n * Represents a time of day with no date and no time zone.\n * @remarks\n * Deliberately not a JavaScript `Date`. A `Date` needs a date, and a time of day has none: `new Date('14:30:45')`\n * is not an instant pinned to some default day, it is `Invalid Date`. The value is destroyed outright rather than\n * merely shifted, which makes this the starker of the two temporal cases.\n */\nexport class TimeOnly {\n static readonly [typeKey] = 'TimeOnly';\n\n /**\n * The hour, 0 through 23.\n */\n @field(Number)\n hour!: number;\n\n /**\n * The minute, 0 through 59.\n */\n @field(Number)\n minute!: number;\n\n /**\n * The second, 0 through 59.\n */\n @field(Number)\n second!: number;\n\n /**\n * The millisecond, 0 through 999.\n */\n @field(Number)\n millisecond!: number;\n\n /**\n * Creates a {@link TimeOnly} from its parts.\n * @param hour The hour.\n * @param minute The minute.\n * @param second The second.\n * @param millisecond The millisecond.\n * @returns The {@link TimeOnly}.\n */\n static from(hour: number, minute: number, second: number = 0, millisecond: number = 0): TimeOnly {\n const timeOnly = new TimeOnly();\n timeOnly.hour = hour;\n timeOnly.minute = minute;\n timeOnly.second = second;\n timeOnly.millisecond = millisecond;\n return timeOnly;\n }\n\n /**\n * Parses the ISO-8601 time of day the server sends, `HH:mm`, `HH:mm:ss` or `HH:mm:ss.fffffff`.\n * @param value The value to parse.\n * @returns The {@link TimeOnly}.\n * @remarks\n * The seconds and the fraction are both optional because the server omits them when they are zero, and the\n * fraction carries up to seven digits where JavaScript holds three - so it is truncated rather than rounded,\n * which keeps a parse followed by a render from moving the value forward.\n */\n static parse(value: string): TimeOnly {\n const match = timeOnlyRegex.exec(value);\n if (match === null) {\n throw new Error(`Invalid TimeOnly format: ${value}`);\n }\n\n const fraction = match[4] ? match[4].padEnd(3, '0').substring(0, 3) : '0';\n\n return TimeOnly.from(\n parseInt(match[1], 10),\n parseInt(match[2], 10),\n match[3] ? parseInt(match[3], 10) : 0,\n parseInt(fraction, 10));\n }\n\n /**\n * Gets the ISO-8601 representation, `HH:mm:ss` - or `HH:mm:ss.fff` when there is a fractional part.\n * @returns The string.\n */\n toString(): string {\n const hour = this.hour.toString().padStart(2, '0');\n const minute = this.minute.toString().padStart(2, '0');\n const second = this.second.toString().padStart(2, '0');\n const time = `${hour}:${minute}:${second}`;\n return this.millisecond > 0 ? `${time}.${this.millisecond.toString().padStart(3, '0')}` : time;\n }\n\n /**\n * Determines whether this is the same time of day as another.\n * @param other The other time.\n * @returns True when they are the same time.\n */\n equals(other: TimeOnly | undefined | null): boolean {\n return !!other &&\n this.hour === other.hour &&\n this.minute === other.minute &&\n this.second === other.second &&\n this.millisecond === other.millisecond;\n }\n}\n"],"names":["typeKey","__decorate","field"],"mappings":";;;;;;AAMA,MAAM,aAAa,GAAG,gDAAgD;MASzD,QAAQ,CAAA;AACjB,IAAA,QAAiBA,eAAO,IAAI,UAAU;AAMtC,IAAA,IAAI;AAMJ,IAAA,MAAM;AAMN,IAAA,MAAM;AAMN,IAAA,WAAW;IAUX,OAAO,IAAI,CAAC,IAAY,EAAE,MAAc,EAAE,MAAA,GAAiB,CAAC,EAAE,WAAA,GAAsB,CAAC,EAAA;AACjF,QAAA,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE;AAC/B,QAAA,QAAQ,CAAC,IAAI,GAAG,IAAI;AACpB,QAAA,QAAQ,CAAC,MAAM,GAAG,MAAM;AACxB,QAAA,QAAQ,CAAC,MAAM,GAAG,MAAM;AACxB,QAAA,QAAQ,CAAC,WAAW,GAAG,WAAW;AAClC,QAAA,OAAO,QAAQ;IACnB;IAWA,OAAO,KAAK,CAAC,KAAa,EAAA;QACtB,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC;AACvC,QAAA,IAAI,KAAK,KAAK,IAAI,EAAE;AAChB,YAAA,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAA,CAAE,CAAC;QACxD;AAEA,QAAA,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,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MAAM;AAC5B,YAAA,IAAI,CAAC,WAAW,KAAK,KAAK,CAAC,WAAW;IAC9C;;AApFAC,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACA,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAMdD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACE,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAMhBD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACE,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAMhBD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACO,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;;"}
|
package/dist/cjs/TimeSpan.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeSpan.js","sources":["../../TimeSpan.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { typeKey } from './typeKey';\n\nimport { field } from './fieldDecorator';\n\nconst timeSpanRegex = /^(-)?(?:(\\d+)\\.)?(\\d{1,2}):(\\d{2}):(\\d{2})(?:\\.(\\d{1,7}))?$/;\n\n/**\n * Represents a time interval.\n */\nexport class TimeSpan {\n static readonly [typeKey] = 'TimeSpan';\n\n \n @field(Number)\n ticks!: number;\n\n @field(Number)\n days!: number;\n\n @field(Number)\n hours!: number;\n\n @field(Number)\n milliseconds!: number;\n\n @field(Number)\n microseconds!: number;\n\n @field(Number)\n nanoseconds!: number;\n\n @field(Number)\n minutes!: number;\n\n @field(Number)\n seconds!: number;\n\n @field(Number)\n totalDays!: number;\n\n @field(Number)\n totalHours!: number;\n\n @field(Number)\n totalMilliseconds!: number;\n\n @field(Number)\n totalMicroseconds!: number;\n\n @field(Number)\n totalNanoseconds!: number;\n\n @field(Number)\n totalMinutes!: number;\n\n @field(Number)\n totalSeconds!: number;\n\n /**\n * Parses a C# compatible TimeSpan string and returns a TimeSpan instance.\n * The string format should match: [-][d.]hh:mm:ss[.fffffff]\n * @param {string} value String representation of TimeSpan.\n * @returns {TimeSpan} A TimeSpan instance with all properties populated.\n * @throws {Error} If the string format is invalid.\n */\n static parse(value: string): TimeSpan {\n const match = timeSpanRegex.exec(value);\n if (match === null) {\n throw new Error(`Invalid TimeSpan format: ${value}`);\n }\n\n const isNegative = match[1] === '-';\n const days = match[2] ? parseInt(match[2], 10) : 0;\n const hours = parseInt(match[3], 10);\n const minutes = parseInt(match[4], 10);\n const seconds = parseInt(match[5], 10);\n const fractionalSeconds = match[6] ? match[6].padEnd(7, '0') : '0000000';\n\n const ticksPerDay = 864000000000;\n const ticksPerHour = 36000000000;\n const ticksPerMinute = 600000000;\n const ticksPerSecond = 10000000;\n\n const ticks =\n days * ticksPerDay +\n hours * ticksPerHour +\n minutes * ticksPerMinute +\n seconds * ticksPerSecond +\n parseInt(fractionalSeconds, 10);\n\n const finalTicks = isNegative ? -ticks : ticks;\n\n const timeSpan = new TimeSpan();\n timeSpan.ticks = finalTicks;\n timeSpan.days = Math.floor(Math.abs(finalTicks) / ticksPerDay) * (isNegative ? -1 : 1);\n timeSpan.hours = Math.floor((Math.abs(finalTicks) / ticksPerHour) % 24);\n timeSpan.minutes = Math.floor((Math.abs(finalTicks) / ticksPerMinute) % 60);\n timeSpan.seconds = Math.floor((Math.abs(finalTicks) / ticksPerSecond) % 60);\n timeSpan.milliseconds = Math.floor((Math.abs(finalTicks) / 10000) % 1000);\n timeSpan.microseconds = Math.floor((Math.abs(finalTicks) / 10) % 1000);\n timeSpan.nanoseconds = Math.floor((Math.abs(finalTicks) % 10) * 100);\n timeSpan.totalDays = finalTicks / ticksPerDay;\n timeSpan.totalHours = finalTicks / ticksPerHour;\n timeSpan.totalMinutes = finalTicks / ticksPerMinute;\n timeSpan.totalSeconds = finalTicks / ticksPerSecond;\n timeSpan.totalMilliseconds = finalTicks / 10000;\n timeSpan.totalMicroseconds = finalTicks / 10;\n timeSpan.totalNanoseconds = finalTicks * 100;\n\n return timeSpan;\n }\n\n /**\n * Converts the TimeSpan to a C# compatible string format.\n * Returns the TimeSpan in format: [-][d.]hh:mm:ss[.fffffff]\n * @returns {string} C# compatible TimeSpan string representation.\n */\n toString(): string {\n const isNegative = this.ticks < 0;\n const absTicks = Math.abs(this.ticks);\n\n const ticksPerDay = 864000000000;\n const ticksPerHour = 36000000000;\n const ticksPerMinute = 600000000;\n const ticksPerSecond = 10000000;\n\n const days = Math.floor(absTicks / ticksPerDay);\n const hours = Math.floor((absTicks / ticksPerHour) % 24);\n const minutes = Math.floor((absTicks / ticksPerMinute) % 60);\n const seconds = Math.floor((absTicks / ticksPerSecond) % 60);\n const fractionalTicks = absTicks % ticksPerSecond;\n\n const parts: string[] = [];\n\n if (isNegative) {\n parts.push('-');\n }\n\n if (days > 0) {\n parts.push(`${days}.`);\n }\n\n parts.push(`${hours.toString().padStart(2, '0')}:`);\n parts.push(`${minutes.toString().padStart(2, '0')}:`);\n parts.push(`${seconds.toString().padStart(2, '0')}`);\n\n if (fractionalTicks > 0) {\n const fractionalStr = fractionalTicks.toString().padStart(7, '0').replace(/0+$/, '');\n parts.push(`.${fractionalStr}`);\n }\n\n return parts.join('');\n }\n\n /**\n * Converts the TimeSpan to a JSON string that works in JSON serialization.\n * Returns the TimeSpan in C# compatible format: [-][d.]hh:mm:ss[.fffffff]\n * @returns {string} C# compatible TimeSpan string representation.\n */\n toJSON(): string {\n return this.toString();\n }\n}\n"],"names":["typeKey","__decorate","field"],"mappings":";;;;;;AAOA,MAAM,aAAa,GAAG,6DAA6D;MAKtE,QAAQ,CAAA;AACjB,IAAA,QAAiBA,eAAO,IAAI,UAAU;AAItC,IAAA,KAAK;AAGL,IAAA,IAAI;AAGJ,IAAA,KAAK;AAGL,IAAA,YAAY;AAGZ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AAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AAGtBD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACQ,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"TimeSpan.js","sources":["../../TimeSpan.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { typeKey } from './typeKey';\n\nimport { field } from './fieldDecorator';\n\nconst timeSpanRegex = /^(-)?(?:(\\d+)\\.)?(\\d{1,2}):(\\d{2}):(\\d{2})(?:\\.(\\d{1,7}))?$/;\n\n/**\n * Represents a time interval.\n */\nexport class TimeSpan {\n static readonly [typeKey] = 'TimeSpan';\n\n \n @field(Number)\n ticks!: number;\n\n @field(Number)\n days!: number;\n\n @field(Number)\n hours!: number;\n\n @field(Number)\n milliseconds!: number;\n\n @field(Number)\n microseconds!: number;\n\n @field(Number)\n nanoseconds!: number;\n\n @field(Number)\n minutes!: number;\n\n @field(Number)\n seconds!: number;\n\n @field(Number)\n totalDays!: number;\n\n @field(Number)\n totalHours!: number;\n\n @field(Number)\n totalMilliseconds!: number;\n\n @field(Number)\n totalMicroseconds!: number;\n\n @field(Number)\n totalNanoseconds!: number;\n\n @field(Number)\n totalMinutes!: number;\n\n @field(Number)\n totalSeconds!: number;\n\n /**\n * Parses a C# compatible TimeSpan string and returns a TimeSpan instance.\n * The string format should match: [-][d.]hh:mm:ss[.fffffff]\n * @param {string} value String representation of TimeSpan.\n * @returns {TimeSpan} A TimeSpan instance with all properties populated.\n * @throws {Error} If the string format is invalid.\n */\n static parse(value: string): TimeSpan {\n const match = timeSpanRegex.exec(value);\n if (match === null) {\n throw new Error(`Invalid TimeSpan format: ${value}`);\n }\n\n const isNegative = match[1] === '-';\n const days = match[2] ? parseInt(match[2], 10) : 0;\n const hours = parseInt(match[3], 10);\n const minutes = parseInt(match[4], 10);\n const seconds = parseInt(match[5], 10);\n const fractionalSeconds = match[6] ? match[6].padEnd(7, '0') : '0000000';\n\n const ticksPerDay = 864000000000;\n const ticksPerHour = 36000000000;\n const ticksPerMinute = 600000000;\n const ticksPerSecond = 10000000;\n\n const ticks =\n days * ticksPerDay +\n hours * ticksPerHour +\n minutes * ticksPerMinute +\n seconds * ticksPerSecond +\n parseInt(fractionalSeconds, 10);\n\n const finalTicks = isNegative ? -ticks : ticks;\n\n const timeSpan = new TimeSpan();\n timeSpan.ticks = finalTicks;\n timeSpan.days = Math.floor(Math.abs(finalTicks) / ticksPerDay) * (isNegative ? -1 : 1);\n timeSpan.hours = Math.floor((Math.abs(finalTicks) / ticksPerHour) % 24);\n timeSpan.minutes = Math.floor((Math.abs(finalTicks) / ticksPerMinute) % 60);\n timeSpan.seconds = Math.floor((Math.abs(finalTicks) / ticksPerSecond) % 60);\n timeSpan.milliseconds = Math.floor((Math.abs(finalTicks) / 10000) % 1000);\n timeSpan.microseconds = Math.floor((Math.abs(finalTicks) / 10) % 1000);\n timeSpan.nanoseconds = Math.floor((Math.abs(finalTicks) % 10) * 100);\n timeSpan.totalDays = finalTicks / ticksPerDay;\n timeSpan.totalHours = finalTicks / ticksPerHour;\n timeSpan.totalMinutes = finalTicks / ticksPerMinute;\n timeSpan.totalSeconds = finalTicks / ticksPerSecond;\n timeSpan.totalMilliseconds = finalTicks / 10000;\n timeSpan.totalMicroseconds = finalTicks / 10;\n timeSpan.totalNanoseconds = finalTicks * 100;\n\n return timeSpan;\n }\n\n /**\n * Converts the TimeSpan to a C# compatible string format.\n * Returns the TimeSpan in format: [-][d.]hh:mm:ss[.fffffff]\n * @returns {string} C# compatible TimeSpan string representation.\n */\n toString(): string {\n const isNegative = this.ticks < 0;\n const absTicks = Math.abs(this.ticks);\n\n const ticksPerDay = 864000000000;\n const ticksPerHour = 36000000000;\n const ticksPerMinute = 600000000;\n const ticksPerSecond = 10000000;\n\n const days = Math.floor(absTicks / ticksPerDay);\n const hours = Math.floor((absTicks / ticksPerHour) % 24);\n const minutes = Math.floor((absTicks / ticksPerMinute) % 60);\n const seconds = Math.floor((absTicks / ticksPerSecond) % 60);\n const fractionalTicks = absTicks % ticksPerSecond;\n\n const parts: string[] = [];\n\n if (isNegative) {\n parts.push('-');\n }\n\n if (days > 0) {\n parts.push(`${days}.`);\n }\n\n parts.push(`${hours.toString().padStart(2, '0')}:`);\n parts.push(`${minutes.toString().padStart(2, '0')}:`);\n parts.push(`${seconds.toString().padStart(2, '0')}`);\n\n if (fractionalTicks > 0) {\n const fractionalStr = fractionalTicks.toString().padStart(7, '0').replace(/0+$/, '');\n parts.push(`.${fractionalStr}`);\n }\n\n return parts.join('');\n }\n\n /**\n * Converts the TimeSpan to a JSON string that works in JSON serialization.\n * Returns the TimeSpan in C# compatible format: [-][d.]hh:mm:ss[.fffffff]\n * @returns {string} C# compatible TimeSpan string representation.\n */\n toJSON(): string {\n return this.toString();\n }\n}\n"],"names":["typeKey","__decorate","field"],"mappings":";;;;;;AAOA,MAAM,aAAa,GAAG,6DAA6D;MAKtE,QAAQ,CAAA;AACjB,IAAA,QAAiBA,eAAO,IAAI,UAAU;AAItC,IAAA,KAAK;AAGL,IAAA,IAAI;AAGJ,IAAA,KAAK;AAGL,IAAA,YAAY;AAGZ,IAAA,YAAY;AAGZ,IAAA,WAAW;AAGX,IAAA,OAAO;AAGP,IAAA,OAAO;AAGP,IAAA,SAAS;AAGT,IAAA,UAAU;AAGV,IAAA,iBAAiB;AAGjB,IAAA,iBAAiB;AAGjB,IAAA,gBAAgB;AAGhB,IAAA,YAAY;AAGZ,IAAA,YAAY;IASZ,OAAO,KAAK,CAAC,KAAa,EAAA;QACtB,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC;AACvC,QAAA,IAAI,KAAK,KAAK,IAAI,EAAE;AAChB,YAAA,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAA,CAAE,CAAC;QACxD;QAEA,MAAM,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;AAGjBD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACG,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAGjBD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACK,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAGnBD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACM,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,YAAA,EAAA,MAAA,CAAA;AAGpBD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACa,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,mBAAA,EAAA,MAAA,CAAA;AAG3BD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACa,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,mBAAA,EAAA,MAAA,CAAA;AAG3BD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACY,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,MAAA,CAAA;AAG1BD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACQ,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AAGtBD,iBAAA,CAAA;IADCC,oBAAK,CAAC,MAAM,CAAC;;AACQ,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;;"}
|
package/dist/cjs/ValueMap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValueMap.js","sources":["../../ValueMap.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\nimport { typeKey } from './typeKey';\n\n/**\n * Represents a map that compares object keys by value.\n */\nexport class ValueMap<TKey, TValue> {\n static readonly [typeKey] = 'ValueMap';\n\n private readonly _entries: Array<[TKey, TValue]> = [];\n\n /**\n * Adds a new entry or updates an existing entry for the provided key.\n *\n * @param key Key to add or update.\n * @param value Value to associate with the key.\n * @returns The current map instance for chaining.\n */\n set(key: TKey, value: TValue): this {\n const index = this._entries.findIndex(([existingKey]) => this.equals(existingKey, key));\n if (index >= 0) {\n this._entries[index][1] = value;\n } else {\n this._entries.push([key, value]);\n }\n\n return this;\n }\n\n /**\n * Gets the value associated with the provided key.\n *\n * @param key Key to look up.\n * @returns The matching value, or undefined when no entry matches.\n */\n get(key: TKey): TValue | undefined {\n return this._entries.find(([existingKey]) => this.equals(existingKey, key))?.[1];\n }\n\n /**\n * Gets an iterator over all key-value entries in insertion order.\n *\n * @returns Iterator for the map entries.\n */\n entries(): IterableIterator<[TKey, TValue]> {\n return this._entries.values();\n }\n\n private equals(first: TKey, second: TKey): boolean {\n if (first === second) {\n return true;\n }\n\n if (first === undefined || first === null || second === undefined || second === null) {\n return false;\n }\n\n if (typeof first === 'object' && typeof second === 'object') {\n return JSON.stringify(first) === JSON.stringify(second);\n }\n\n return false;\n }\n}"],"names":["typeKey"],"mappings":";;;;MAOa,QAAQ,CAAA;AACjB,IAAA,QAAiBA,eAAO,IAAI,UAAU;IAErB,QAAQ,GAA0B,EAAE;IASrD,GAAG,CAAC,GAAS,EAAE,KAAa,EAAA;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AACvF,QAAA,IAAI,KAAK,IAAI,CAAC,EAAE;YACZ,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK;QACnC;aAAO;YACH,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACpC;AAEA,QAAA,OAAO,IAAI;IACf;AAQA,IAAA,GAAG,CAAC,GAAS,EAAA;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACpF;IAOA,OAAO,GAAA;AACH,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;IACjC;IAEQ,MAAM,CAAC,KAAW,EAAE,MAAY,EAAA;AACpC,QAAA,IAAI,KAAK,KAAK,MAAM,EAAE;AAClB,YAAA,OAAO,IAAI;QACf;AAEA,QAAA,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,EAAE;AAClF,YAAA,OAAO,KAAK;QAChB;QAEA,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;AACzD,YAAA,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;QAC3D;AAEA,QAAA,OAAO,KAAK;IAChB
|
|
1
|
+
{"version":3,"file":"ValueMap.js","sources":["../../ValueMap.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\nimport { typeKey } from './typeKey';\n\n/**\n * Represents a map that compares object keys by value.\n */\nexport class ValueMap<TKey, TValue> {\n static readonly [typeKey] = 'ValueMap';\n\n private readonly _entries: Array<[TKey, TValue]> = [];\n\n /**\n * Adds a new entry or updates an existing entry for the provided key.\n *\n * @param key Key to add or update.\n * @param value Value to associate with the key.\n * @returns The current map instance for chaining.\n */\n set(key: TKey, value: TValue): this {\n const index = this._entries.findIndex(([existingKey]) => this.equals(existingKey, key));\n if (index >= 0) {\n this._entries[index][1] = value;\n } else {\n this._entries.push([key, value]);\n }\n\n return this;\n }\n\n /**\n * Gets the value associated with the provided key.\n *\n * @param key Key to look up.\n * @returns The matching value, or undefined when no entry matches.\n */\n get(key: TKey): TValue | undefined {\n return this._entries.find(([existingKey]) => this.equals(existingKey, key))?.[1];\n }\n\n /**\n * Gets an iterator over all key-value entries in insertion order.\n *\n * @returns Iterator for the map entries.\n */\n entries(): IterableIterator<[TKey, TValue]> {\n return this._entries.values();\n }\n\n private equals(first: TKey, second: TKey): boolean {\n if (first === second) {\n return true;\n }\n\n if (first === undefined || first === null || second === undefined || second === null) {\n return false;\n }\n\n if (typeof first === 'object' && typeof second === 'object') {\n return JSON.stringify(first) === JSON.stringify(second);\n }\n\n return false;\n }\n}"],"names":["typeKey"],"mappings":";;;;MAOa,QAAQ,CAAA;AACjB,IAAA,QAAiBA,eAAO,IAAI,UAAU;IAErB,QAAQ,GAA0B,EAAE;IASrD,GAAG,CAAC,GAAS,EAAE,KAAa,EAAA;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AACvF,QAAA,IAAI,KAAK,IAAI,CAAC,EAAE;YACZ,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK;QACnC;aAAO;YACH,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACpC;AAEA,QAAA,OAAO,IAAI;IACf;AAQA,IAAA,GAAG,CAAC,GAAS,EAAA;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACpF;IAOA,OAAO,GAAA;AACH,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;IACjC;IAEQ,MAAM,CAAC,KAAW,EAAE,MAAY,EAAA;AACpC,QAAA,IAAI,KAAK,KAAK,MAAM,EAAE;AAClB,YAAA,OAAO,IAAI;QACf;AAEA,QAAA,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,EAAE;AAClF,YAAA,OAAO,KAAK;QAChB;QAEA,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;AACzD,YAAA,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;QAC3D;AAEA,QAAA,OAAO,KAAK;IAChB;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_tslib.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_tslib.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derivedTypeDecorator.js","sources":["../../derivedTypeDecorator.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport './reflection';\nimport { Constructor } from './Constructor';\nimport { DerivedType } from './DerivedType';\nimport { StandardClassDecoratorContext } from './StandardClassDecoratorContext';\n\nexport function derivedType(identifier: string, targetType?: Constructor) {\n function decorator<Target extends Constructor>(target: Target): void;\n function decorator<Target extends Constructor>(target: Target, context: StandardClassDecoratorContext<Target>): void;\n function decorator(target: Constructor, context?: StandardClassDecoratorContext<Constructor>): void {\n if (typeof target !== 'function') throw new TypeError('@derivedType can only decorate classes');\n if (context && context.kind !== 'class') throw new TypeError('@derivedType can only decorate classes');\n if (context && typeof context.addInitializer !== 'function') throw new TypeError('@derivedType requires a standard class decorator context');\n\n if (context) {\n context.addInitializer(function (this: Constructor): void {\n register(this);\n });\n return;\n }\n\n register(target);\n }\n\n function register(target: Constructor): void {\n DerivedType.set(target, identifier, targetType);\n\n // Auto-register with every class in the prototype chain so that JsonSerializer\n // can discover all derived types via DerivedType.getDerivedTypesFor() at runtime,\n // without requiring the parent type to import each subtype (which causes circular deps).\n let proto = Object.getPrototypeOf(target.prototype);\n while (proto && proto.constructor && proto.constructor !== Object) {\n DerivedType.set(target, identifier, proto.constructor);\n proto = Object.getPrototypeOf(proto);\n }\n }\n\n return decorator;\n}\n"],"names":["DerivedType"],"mappings":";;;;;AAQM,SAAU,WAAW,CAAC,UAAkB,EAAE,UAAwB,EAAA;AAGpE,IAAA,SAAS,SAAS,CAAC,MAAmB,EAAE,OAAoD,EAAA;QACxF,IAAI,OAAO,MAAM,KAAK,UAAU;AAAE,YAAA,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC;AAC/F,QAAA,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO;AAAE,YAAA,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC;AACtG,QAAA,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,cAAc,KAAK,UAAU;AAAE,YAAA,MAAM,IAAI,SAAS,CAAC,0DAA0D,CAAC;QAE5I,IAAI,OAAO,EAAE;YACT,OAAO,CAAC,cAAc,CAAC,YAAA;gBACnB,QAAQ,CAAC,IAAI,CAAC;AAClB,YAAA,CAAC,CAAC;YACF;QACJ;QAEA,QAAQ,CAAC,MAAM,CAAC;IACpB;IAEA,SAAS,QAAQ,CAAC,MAAmB,EAAA;QACjCA,uBAAW,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC;QAK/C,IAAI,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC;AACnD,QAAA,OAAO,KAAK,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,KAAK,MAAM,EAAE;YAC/DA,uBAAW,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,WAAW,CAAC;AACtD,YAAA,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC;QACxC;IACJ;AAEA,IAAA,OAAO,SAAS;AACpB
|
|
1
|
+
{"version":3,"file":"derivedTypeDecorator.js","sources":["../../derivedTypeDecorator.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport './reflection';\nimport { Constructor } from './Constructor';\nimport { DerivedType } from './DerivedType';\nimport { StandardClassDecoratorContext } from './StandardClassDecoratorContext';\n\nexport function derivedType(identifier: string, targetType?: Constructor) {\n function decorator<Target extends Constructor>(target: Target): void;\n function decorator<Target extends Constructor>(target: Target, context: StandardClassDecoratorContext<Target>): void;\n function decorator(target: Constructor, context?: StandardClassDecoratorContext<Constructor>): void {\n if (typeof target !== 'function') throw new TypeError('@derivedType can only decorate classes');\n if (context && context.kind !== 'class') throw new TypeError('@derivedType can only decorate classes');\n if (context && typeof context.addInitializer !== 'function') throw new TypeError('@derivedType requires a standard class decorator context');\n\n if (context) {\n context.addInitializer(function (this: Constructor): void {\n register(this);\n });\n return;\n }\n\n register(target);\n }\n\n function register(target: Constructor): void {\n DerivedType.set(target, identifier, targetType);\n\n // Auto-register with every class in the prototype chain so that JsonSerializer\n // can discover all derived types via DerivedType.getDerivedTypesFor() at runtime,\n // without requiring the parent type to import each subtype (which causes circular deps).\n let proto = Object.getPrototypeOf(target.prototype);\n while (proto && proto.constructor && proto.constructor !== Object) {\n DerivedType.set(target, identifier, proto.constructor);\n proto = Object.getPrototypeOf(proto);\n }\n }\n\n return decorator;\n}\n"],"names":["DerivedType"],"mappings":";;;;;AAQM,SAAU,WAAW,CAAC,UAAkB,EAAE,UAAwB,EAAA;AAGpE,IAAA,SAAS,SAAS,CAAC,MAAmB,EAAE,OAAoD,EAAA;QACxF,IAAI,OAAO,MAAM,KAAK,UAAU;AAAE,YAAA,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC;AAC/F,QAAA,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO;AAAE,YAAA,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC;AACtG,QAAA,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,cAAc,KAAK,UAAU;AAAE,YAAA,MAAM,IAAI,SAAS,CAAC,0DAA0D,CAAC;QAE5I,IAAI,OAAO,EAAE;YACT,OAAO,CAAC,cAAc,CAAC,YAAA;gBACnB,QAAQ,CAAC,IAAI,CAAC;AAClB,YAAA,CAAC,CAAC;YACF;QACJ;QAEA,QAAQ,CAAC,MAAM,CAAC;IACpB;IAEA,SAAS,QAAQ,CAAC,MAAmB,EAAA;QACjCA,uBAAW,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC;QAK/C,IAAI,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC;AACnD,QAAA,OAAO,KAAK,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,KAAK,MAAM,EAAE;YAC/DA,uBAAW,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,WAAW,CAAC;AACtD,YAAA,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC;QACxC;IACJ;AAEA,IAAA,OAAO,SAAS;AACpB;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"duplicateInstanceGuard.js","sources":["../../duplicateInstanceGuard.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * Detects that more than one copy of this package has been loaded into the same JavaScript\n * realm and reports it, once.\n *\n * A second copy brings its own converter registry and its own `Guid` and `ConceptAs` class\n * objects. Values themselves survive the boundary - a convertible type is recognized by the key\n * it declares rather than by its class object - but three things do not, all of them silent:\n * a converter registered through `JsonSerializer.registerConverter` reaches only the copy it was\n * registered on, an `instanceof` against the other copy's class is false, and a version pinned at\n * the top level never reaches a copy nested under a dependency, so an adopted fix can reach\n * nothing at all.\n *\n * A package manager is free to produce that second copy, and this module does not try to stop\n * it. It makes it visible. Two installs is the usual cause, but one install reached as both ESM\n * and CommonJS is the same failure with no version mismatch anywhere to find it by - so the\n * report names where each load came from rather than only how many there were.\n *\n * A copy older than this guard does not register itself and leaves nothing behind for a newer\n * copy to find, so duplication is reported only once every copy in the realm carries the guard.\n * That is inherent to the approach, not a gap left to close.\n *\n * The bookkeeping lives on `globalThis`, because module scope is the very thing being\n * duplicated. Its two keys are a cross-version contract - a copy of a *different* version of\n * this package may have written them first - so the shapes are deliberately primitive: an\n * array of strings and a boolean.\n *\n * The registration is a load-bearing side effect. Do not declare `\"sideEffects\": false` in the\n * package manifest; a bundler would then be free to drop it, and the duplicate would go back\n * to being silent.\n */\n\n/** Holds one entry per loaded copy of this package, in load order. */\nconst loadedInstancesKey = Symbol.for('@cratis/fundamentals.loadedInstances');\n\n/** Records that the duplicate has been reported, so it is reported exactly once per realm. */\nconst duplicateReportedKey = Symbol.for('@cratis/fundamentals.duplicateReported');\n\nconst globals = globalThis as Record<symbol, unknown>;\n\n/** Placeholder used when the runtime offers no usable stack trace. */\nconst unknownOrigin = 'unknown location';\n\n/** Set once this copy has registered itself, so repeated calls count it only once. */\nlet registered = false;\n\n/**\n * Resolves where this copy of the package was loaded from, so the report can name the copies\n * rather than only their number.\n * @returns {string} A source location, or a placeholder when no stack trace is available.\n */\nconst resolveOrigin = (): string => {\n try {\n // The first frame is this function, which lives in this copy of the package - exactly\n // the location worth naming. V8 prefixes the stack with a bare `Error` line that other\n // engines omit, so drop it rather than indexing past it.\n const frames = (new Error().stack ?? '')\n .split('\\n')\n .map(line => line.trim())\n .filter(line => line.length > 0 && line !== 'Error');\n\n const frame = frames[0];\n if (!frame) return unknownOrigin;\n\n return frame.match(/\\((.+)\\)$/)?.[1] ?? frame.replace(/^at\\s+/, '');\n } catch {\n // A runtime that refuses stack traces is not a reason to skip the registration.\n return unknownOrigin;\n }\n};\n\n/**\n * Writes the diagnostic as a single console entry naming the problem, its consequence and the\n * way out.\n * @param {string[]} origins Where each loaded copy was loaded from, in load order.\n */\nconst reportDuplicate = (origins: string[]): void => {\n if (typeof console === 'undefined' || typeof console.warn !== 'function') return;\n\n const locations = origins.map((origin, index) => ` ${index + 1}. ${origin}`).join('\\n');\n\n console.warn(\n `[@cratis/fundamentals] Loaded ${origins.length} times into the same JavaScript realm, and it has to be loaded once.\\n` +\n 'Each load builds its own converter registry and its own Guid and ConceptAs class objects. A converter registered through ' +\n 'JsonSerializer.registerConverter reaches only the copy it was registered on, an instanceof against the other copy\\'s ' +\n 'class is false, and a version pinned at the top level does not reach a copy nested under a dependency - so an adopted ' +\n `fix can reach nothing at all.\\nLoaded from:\\n${locations}\\n` +\n 'If those are separate installs, collapse them with `yarn dedupe @cratis/fundamentals` (or `npm dedupe`) and confirm with ' +\n '`yarn why @cratis/fundamentals`. If they differ only in dist/esm against dist/cjs it is one install reached as both ESM ' +\n 'and CommonJS, which no dedupe will fix - make every importer resolve the same one.');\n};\n\n/**\n * Registers this copy of the package and reports, once per realm, when it is not the only one.\n * Calling this more than once from the same copy registers that copy once.\n */\nexport const registerModuleInstance = (): void => {\n if (registered) return;\n registered = true;\n\n const existing = globals[loadedInstancesKey];\n const origins: string[] = Array.isArray(existing) ? existing : [];\n if (origins !== existing) {\n globals[loadedInstancesKey] = origins;\n }\n origins.push(resolveOrigin());\n\n if (origins.length < 2 || globals[duplicateReportedKey] === true) return;\n\n globals[duplicateReportedKey] = true;\n reportDuplicate(origins);\n};\n"],"names":[],"mappings":";;AAmCA,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,sCAAsC,CAAC;AAG7E,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,wCAAwC,CAAC;AAEjF,MAAM,OAAO,GAAG,UAAq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MAAM,sBAAsB,GAAG,MAAW;AAC7C,IAAA,IAAI,UAAU;QAAE;IAChB,UAAU,GAAG,IAAI;AAEjB,IAAA,MAAM,QAAQ,GAAG,OAAO,CAAC,kBAAkB,CAAC;AAC5C,IAAA,MAAM,OAAO,GAAa,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,GAAG,EAAE;AACjE,IAAA,IAAI,OAAO,KAAK,QAAQ,EAAE;AACtB,QAAA,OAAO,CAAC,kBAAkB,CAAC,GAAG,OAAO;IACzC;AACA,IAAA,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAE7B,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,oBAAoB,CAAC,KAAK,IAAI;QAAE;AAElE,IAAA,OAAO,CAAC,oBAAoB,CAAC,GAAG,IAAI;IACpC,eAAe,CAAC,OAAO,CAAC;AAC5B
|
|
1
|
+
{"version":3,"file":"duplicateInstanceGuard.js","sources":["../../duplicateInstanceGuard.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * Detects that more than one copy of this package has been loaded into the same JavaScript\n * realm and reports it, once.\n *\n * A second copy brings its own converter registry and its own `Guid` and `ConceptAs` class\n * objects. Values themselves survive the boundary - a convertible type is recognized by the key\n * it declares rather than by its class object - but three things do not, all of them silent:\n * a converter registered through `JsonSerializer.registerConverter` reaches only the copy it was\n * registered on, an `instanceof` against the other copy's class is false, and a version pinned at\n * the top level never reaches a copy nested under a dependency, so an adopted fix can reach\n * nothing at all.\n *\n * A package manager is free to produce that second copy, and this module does not try to stop\n * it. It makes it visible. Two installs is the usual cause, but one install reached as both ESM\n * and CommonJS is the same failure with no version mismatch anywhere to find it by - so the\n * report names where each load came from rather than only how many there were.\n *\n * A copy older than this guard does not register itself and leaves nothing behind for a newer\n * copy to find, so duplication is reported only once every copy in the realm carries the guard.\n * That is inherent to the approach, not a gap left to close.\n *\n * The bookkeeping lives on `globalThis`, because module scope is the very thing being\n * duplicated. Its two keys are a cross-version contract - a copy of a *different* version of\n * this package may have written them first - so the shapes are deliberately primitive: an\n * array of strings and a boolean.\n *\n * The registration is a load-bearing side effect. Do not declare `\"sideEffects\": false` in the\n * package manifest; a bundler would then be free to drop it, and the duplicate would go back\n * to being silent.\n */\n\n/** Holds one entry per loaded copy of this package, in load order. */\nconst loadedInstancesKey = Symbol.for('@cratis/fundamentals.loadedInstances');\n\n/** Records that the duplicate has been reported, so it is reported exactly once per realm. */\nconst duplicateReportedKey = Symbol.for('@cratis/fundamentals.duplicateReported');\n\nconst globals = globalThis as Record<symbol, unknown>;\n\n/** Placeholder used when the runtime offers no usable stack trace. */\nconst unknownOrigin = 'unknown location';\n\n/** Set once this copy has registered itself, so repeated calls count it only once. */\nlet registered = false;\n\n/**\n * Resolves where this copy of the package was loaded from, so the report can name the copies\n * rather than only their number.\n * @returns {string} A source location, or a placeholder when no stack trace is available.\n */\nconst resolveOrigin = (): string => {\n try {\n // The first frame is this function, which lives in this copy of the package - exactly\n // the location worth naming. V8 prefixes the stack with a bare `Error` line that other\n // engines omit, so drop it rather than indexing past it.\n const frames = (new Error().stack ?? '')\n .split('\\n')\n .map(line => line.trim())\n .filter(line => line.length > 0 && line !== 'Error');\n\n const frame = frames[0];\n if (!frame) return unknownOrigin;\n\n return frame.match(/\\((.+)\\)$/)?.[1] ?? frame.replace(/^at\\s+/, '');\n } catch {\n // A runtime that refuses stack traces is not a reason to skip the registration.\n return unknownOrigin;\n }\n};\n\n/**\n * Writes the diagnostic as a single console entry naming the problem, its consequence and the\n * way out.\n * @param {string[]} origins Where each loaded copy was loaded from, in load order.\n */\nconst reportDuplicate = (origins: string[]): void => {\n if (typeof console === 'undefined' || typeof console.warn !== 'function') return;\n\n const locations = origins.map((origin, index) => ` ${index + 1}. ${origin}`).join('\\n');\n\n console.warn(\n `[@cratis/fundamentals] Loaded ${origins.length} times into the same JavaScript realm, and it has to be loaded once.\\n` +\n 'Each load builds its own converter registry and its own Guid and ConceptAs class objects. A converter registered through ' +\n 'JsonSerializer.registerConverter reaches only the copy it was registered on, an instanceof against the other copy\\'s ' +\n 'class is false, and a version pinned at the top level does not reach a copy nested under a dependency - so an adopted ' +\n `fix can reach nothing at all.\\nLoaded from:\\n${locations}\\n` +\n 'If those are separate installs, collapse them with `yarn dedupe @cratis/fundamentals` (or `npm dedupe`) and confirm with ' +\n '`yarn why @cratis/fundamentals`. If they differ only in dist/esm against dist/cjs it is one install reached as both ESM ' +\n 'and CommonJS, which no dedupe will fix - make every importer resolve the same one.');\n};\n\n/**\n * Registers this copy of the package and reports, once per realm, when it is not the only one.\n * Calling this more than once from the same copy registers that copy once.\n */\nexport const registerModuleInstance = (): void => {\n if (registered) return;\n registered = true;\n\n const existing = globals[loadedInstancesKey];\n const origins: string[] = Array.isArray(existing) ? existing : [];\n if (origins !== existing) {\n globals[loadedInstancesKey] = origins;\n }\n origins.push(resolveOrigin());\n\n if (origins.length < 2 || globals[duplicateReportedKey] === true) return;\n\n globals[duplicateReportedKey] = true;\n reportDuplicate(origins);\n};\n"],"names":[],"mappings":";;AAmCA,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,sCAAsC,CAAC;AAG7E,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,wCAAwC,CAAC;AAEjF,MAAM,OAAO,GAAG,UAAqC;AAGrD,MAAM,aAAa,GAAG,kBAAkB;AAGxC,IAAI,UAAU,GAAG,KAAK;AAOtB,MAAM,aAAa,GAAG,MAAa;AAC/B,IAAA,IAAI;QAIA,MAAM,MAAM,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,KAAK,IAAI,EAAE;aAClC,KAAK,CAAC,IAAI;aACV,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE;AACvB,aAAA,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,KAAK,OAAO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,IAAI,CAAC,aAAa,EAAE,CAAC;IAE7B,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,oBAAoB,CAAC,KAAK,IAAI;QAAE;AAElE,IAAA,OAAO,CAAC,oBAAoB,CAAC,GAAG,IAAI;IACpC,eAAe,CAAC,OAAO,CAAC;AAC5B;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldDecorator.js","sources":["../../fieldDecorator.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from './Constructor';\nimport { Field } from './Field';\nimport { Fields } from './Fields';\nimport { addFieldToDecoratorMetadata } from './fieldDecoratorMetadata';\nimport { StandardFieldDecoratorContext } from './StandardFieldDecoratorContext';\n\ntype fieldOptions = {\n enumerable?: boolean;\n derivatives?: Constructor[];\n genericArguments?: Constructor[];\n};\n\nconst isFieldOptions = (value: boolean | fieldOptions | undefined): value is fieldOptions => {\n return typeof value === 'object' && value !== null;\n};\n\nexport function field(targetType: Constructor, enumerableOrOptions?: boolean | fieldOptions, derivatives?: Constructor[], genericArguments?: Constructor[]) {\n const enumerable = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.enumerable || false) : (enumerableOrOptions || false);\n const actualDerivatives = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.derivatives || []) : (derivatives || []);\n const actualGenericArguments = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.genericArguments || []) : (genericArguments || []);\n\n function decorator(target: object, propertyKey: string): void;\n function decorator(initialValue: undefined, context: StandardFieldDecoratorContext): void;\n function decorator(targetOrInitialValue: object | undefined, propertyKeyOrContext: string | symbol | StandardFieldDecoratorContext): void {\n if (typeof propertyKeyOrContext === 'object' && propertyKeyOrContext !== null) {\n if (targetOrInitialValue !== undefined) throw new TypeError('@field received an invalid standard field value');\n addStandardField(propertyKeyOrContext);\n return;\n }\n\n addLegacyField(targetOrInitialValue, propertyKeyOrContext);\n }\n\n function addStandardField(context: StandardFieldDecoratorContext): void {\n if (context.kind !== 'field') throw new TypeError('@field can only decorate fields');\n if (context.static) throw new TypeError('@field cannot decorate static fields');\n if (context.private) throw new TypeError('@field cannot decorate private fields');\n if (typeof context.name !== 'string') throw new TypeError('@field cannot decorate symbol-named fields');\n if (!context.metadata) throw new TypeError('@field requires standard decorator metadata support');\n\n addFieldToDecoratorMetadata(\n context.metadata,\n new Field(context.name, targetType, enumerable, actualDerivatives, actualGenericArguments));\n }\n\n function addLegacyField(target: object | undefined, propertyKey: string | symbol): void {\n if (typeof propertyKey === 'symbol') throw new TypeError('@field cannot decorate symbol-named fields');\n if (typeof propertyKey !== 'string') throw new TypeError('@field received an invalid legacy decorator invocation');\n if (!target || typeof target === 'function') throw new TypeError('@field cannot decorate static fields');\n\n Fields.addFieldToType(target.constructor as Constructor, propertyKey, targetType, enumerable, actualDerivatives, actualGenericArguments);\n }\n\n return decorator;\n}\n"],"names":["addFieldToDecoratorMetadata","Field","Fields"],"mappings":";;;;;;AAeA,MAAM,cAAc,GAAG,CAAC,KAAyC,KAA2B;IACxF,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;AACtD,CAAC;AAEK,SAAU,KAAK,CAAC,UAAuB,EAAE,mBAA4C,EAAE,WAA2B,EAAE,gBAAgC,EAAA;IACtJ,MAAM,UAAU,GAAG,cAAc,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,UAAU,IAAI,KAAK,KAAK,mBAAmB,IAAI,KAAK,CAAC;IACnI,MAAM,iBAAiB,GAAG,cAAc,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,WAAW,IAAI,EAAE,KAAK,WAAW,IAAI,EAAE,CAAC;IAC7H,MAAM,sBAAsB,GAAG,cAAc,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,gBAAgB,IAAI,EAAE,KAAK,gBAAgB,IAAI,EAAE,CAAC;AAI5I,I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M,IAAI,OAAO,MAAM,KAAK,UAAU;AAAE,YAAA,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC;AAExG,QAAAC,aAAM,CAAC,cAAc,CAAC,MAAM,CAAC,WAA0B,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,sBAAsB,CAAC;IAC5I;AAEA,IAAA,OAAO,SAAS;AACpB
|
|
1
|
+
{"version":3,"file":"fieldDecorator.js","sources":["../../fieldDecorator.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from './Constructor';\nimport { Field } from './Field';\nimport { Fields } from './Fields';\nimport { addFieldToDecoratorMetadata } from './fieldDecoratorMetadata';\nimport { StandardFieldDecoratorContext } from './StandardFieldDecoratorContext';\n\ntype fieldOptions = {\n enumerable?: boolean;\n derivatives?: Constructor[];\n genericArguments?: Constructor[];\n};\n\nconst isFieldOptions = (value: boolean | fieldOptions | undefined): value is fieldOptions => {\n return typeof value === 'object' && value !== null;\n};\n\nexport function field(targetType: Constructor, enumerableOrOptions?: boolean | fieldOptions, derivatives?: Constructor[], genericArguments?: Constructor[]) {\n const enumerable = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.enumerable || false) : (enumerableOrOptions || false);\n const actualDerivatives = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.derivatives || []) : (derivatives || []);\n const actualGenericArguments = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.genericArguments || []) : (genericArguments || []);\n\n function decorator(target: object, propertyKey: string): void;\n function decorator(initialValue: undefined, context: StandardFieldDecoratorContext): void;\n function decorator(targetOrInitialValue: object | undefined, propertyKeyOrContext: string | symbol | StandardFieldDecoratorContext): void {\n if (typeof propertyKeyOrContext === 'object' && propertyKeyOrContext !== null) {\n if (targetOrInitialValue !== undefined) throw new TypeError('@field received an invalid standard field value');\n addStandardField(propertyKeyOrContext);\n return;\n }\n\n addLegacyField(targetOrInitialValue, propertyKeyOrContext);\n }\n\n function addStandardField(context: StandardFieldDecoratorContext): void {\n if (context.kind !== 'field') throw new TypeError('@field can only decorate fields');\n if (context.static) throw new TypeError('@field cannot decorate static fields');\n if (context.private) throw new TypeError('@field cannot decorate private fields');\n if (typeof context.name !== 'string') throw new TypeError('@field cannot decorate symbol-named fields');\n if (!context.metadata) throw new TypeError('@field requires standard decorator metadata support');\n\n addFieldToDecoratorMetadata(\n context.metadata,\n new Field(context.name, targetType, enumerable, actualDerivatives, actualGenericArguments));\n }\n\n function addLegacyField(target: object | undefined, propertyKey: string | symbol): void {\n if (typeof propertyKey === 'symbol') throw new TypeError('@field cannot decorate symbol-named fields');\n if (typeof propertyKey !== 'string') throw new TypeError('@field received an invalid legacy decorator invocation');\n if (!target || typeof target === 'function') throw new TypeError('@field cannot decorate static fields');\n\n Fields.addFieldToType(target.constructor as Constructor, propertyKey, targetType, enumerable, actualDerivatives, actualGenericArguments);\n }\n\n return decorator;\n}\n"],"names":["addFieldToDecoratorMetadata","Field","Fields"],"mappings":";;;;;;AAeA,MAAM,cAAc,GAAG,CAAC,KAAyC,KAA2B;IACxF,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;AACtD,CAAC;AAEK,SAAU,KAAK,CAAC,UAAuB,EAAE,mBAA4C,EAAE,WAA2B,EAAE,gBAAgC,EAAA;IACtJ,MAAM,UAAU,GAAG,cAAc,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,UAAU,IAAI,KAAK,KAAK,mBAAmB,IAAI,KAAK,CAAC;IACnI,MAAM,iBAAiB,GAAG,cAAc,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,WAAW,IAAI,EAAE,KAAK,WAAW,IAAI,EAAE,CAAC;IAC7H,MAAM,sBAAsB,GAAG,cAAc,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,gBAAgB,IAAI,EAAE,KAAK,gBAAgB,IAAI,EAAE,CAAC;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AAC,MAAM,IAAI,OAAO,MAAM,KAAK,UAAU;AAAE,YAAA,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC;AAExG,QAAAC,aAAM,CAAC,cAAc,CAAC,MAAM,CAAC,WAA0B,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,sBAAsB,CAAC;IAC5I;AAEA,IAAA,OAAO,SAAS;AACpB;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldDecoratorMetadata.js","sources":["../../fieldDecoratorMetadata.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport './reflection';\nimport { Constructor } from './Constructor';\nimport { Field } from './Field';\n\nconst fieldsMetadataKey = Symbol.for('@cratis/fundamentals.fields');\n\n/**\n * Adds a field to the metadata object supplied to a standard decorator.\n * @param metadata The class metadata object supplied by the decorator runtime.\n * @param field The field to add.\n */\nexport function addFieldToDecoratorMetadata(metadata: Record<PropertyKey, unknown>, field: Field): void {\n const fields = Reflect.getOwnMetadata(fieldsMetadataKey, metadata) as Map<string, Field> | undefined ?? new Map<string, Field>();\n fields.set(field.name, field);\n Reflect.defineMetadata(fieldsMetadataKey, fields, metadata);\n}\n\n/**\n * Gets the fields stored in the standard decorator metadata owned by a type.\n * @param target The type to read metadata from.\n * @returns The fields declared by the type through standard decorators.\n */\nexport function getOwnDecoratorFieldsForType(target: Constructor): Field[] {\n if (!Object.prototype.hasOwnProperty.call(target, Symbol.metadata)) return [];\n\n const metadata = (target as Constructor & { [Symbol.metadata]?: Record<PropertyKey, unknown> | null })[Symbol.metadata];\n if (!metadata) return [];\n\n const fields = Reflect.getOwnMetadata(fieldsMetadataKey, metadata) as Map<string, Field> | undefined;\n return fields ? [...fields.values()] : [];\n}\n"],"names":[],"mappings":";;;;AAOA,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC;AAO7D,SAAU,2BAA2B,CAAC,QAAsC,EAAE,KAAY,EAAA;AAC5F,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,iBAAiB,EAAE,QAAQ,CAAmC,IAAI,IAAI,GAAG,EAAiB;IAChI,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;IAC7B,OAAO,CAAC,cAAc,CAAC,iBAAiB,EAAE,MAAM,EAAE,QAAQ,CAAC;AAC/D;AAOM,SAAU,4BAA4B,CAAC,MAAmB,EAAA;AAC5D,IAAA,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC;AAAE,QAAA,OAAO,EAAE;IAE7E,MAAM,QAAQ,GAAI,MAAoF,CAAC,MAAM,CAAC,QAAQ,CAAC;AACvH,IAAA,IAAI,CAAC,QAAQ;AAAE,QAAA,OAAO,EAAE;IAExB,MAAM,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,iBAAiB,EAAE,QAAQ,CAAmC;AACpG,IAAA,OAAO,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;AAC7C
|
|
1
|
+
{"version":3,"file":"fieldDecoratorMetadata.js","sources":["../../fieldDecoratorMetadata.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport './reflection';\nimport { Constructor } from './Constructor';\nimport { Field } from './Field';\n\nconst fieldsMetadataKey = Symbol.for('@cratis/fundamentals.fields');\n\n/**\n * Adds a field to the metadata object supplied to a standard decorator.\n * @param metadata The class metadata object supplied by the decorator runtime.\n * @param field The field to add.\n */\nexport function addFieldToDecoratorMetadata(metadata: Record<PropertyKey, unknown>, field: Field): void {\n const fields = Reflect.getOwnMetadata(fieldsMetadataKey, metadata) as Map<string, Field> | undefined ?? new Map<string, Field>();\n fields.set(field.name, field);\n Reflect.defineMetadata(fieldsMetadataKey, fields, metadata);\n}\n\n/**\n * Gets the fields stored in the standard decorator metadata owned by a type.\n * @param target The type to read metadata from.\n * @returns The fields declared by the type through standard decorators.\n */\nexport function getOwnDecoratorFieldsForType(target: Constructor): Field[] {\n if (!Object.prototype.hasOwnProperty.call(target, Symbol.metadata)) return [];\n\n const metadata = (target as Constructor & { [Symbol.metadata]?: Record<PropertyKey, unknown> | null })[Symbol.metadata];\n if (!metadata) return [];\n\n const fields = Reflect.getOwnMetadata(fieldsMetadataKey, metadata) as Map<string, Field> | undefined;\n return fields ? [...fields.values()] : [];\n}\n"],"names":[],"mappings":";;;;AAOA,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC;AAO7D,SAAU,2BAA2B,CAAC,QAAsC,EAAE,KAAY,EAAA;AAC5F,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,iBAAiB,EAAE,QAAQ,CAAmC,IAAI,IAAI,GAAG,EAAiB;IAChI,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;IAC7B,OAAO,CAAC,cAAc,CAAC,iBAAiB,EAAE,MAAM,EAAE,QAAQ,CAAC;AAC/D;AAOM,SAAU,4BAA4B,CAAC,MAAmB,EAAA;AAC5D,IAAA,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC;AAAE,QAAA,OAAO,EAAE;IAE7E,MAAM,QAAQ,GAAI,MAAoF,CAAC,MAAM,CAAC,QAAQ,CAAC;AACvH,IAAA,IAAI,CAAC,QAAQ;AAAE,QAAA,OAAO,EAAE;IAExB,MAAM,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,iBAAiB,EAAE,QAAQ,CAAmC;AACpG,IAAA,OAAO,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;AAC7C;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineString.js","sources":["../../../geospatial/LineString.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Point } from './Point';\nimport { typeKey } from '../typeKey';\n\n/**\n * Represents a line string composed of two or more points.\n */\nexport class LineString {\n static readonly [typeKey] = 'LineString';\n\n coordinates!: Point[];\n\n /**\n * Creates a new LineString instance.\n * @param {Point[]} coordinates - The points that make up the line string (minimum 2 points).\n */\n constructor(coordinates: Point[]) {\n if (coordinates.length < 2) {\n throw new Error('LineString must have at least 2 points');\n }\n this.coordinates = coordinates;\n }\n\n /**\n * Converts the LineString to a GeoJSON representation.\n * @returns {object} GeoJSON representation.\n */\n toJSON(): object {\n return {\n type: 'LineString',\n coordinates: this.coordinates.map(p => [p.longitude, p.latitude])\n };\n }\n}\n"],"names":["typeKey"],"mappings":";;;;MASa,UAAU,CAAA;AACnB,IAAA,QAAiBA,eAAO,IAAI,YAAY;AAExC,IAAA,WAAW;AAMX,IAAA,WAAA,CAAY,WAAoB,EAAA;AAC5B,QAAA,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;AACxB,YAAA,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC;QAC7D;AACA,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW;IAClC;IAMA,MAAM,GAAA;QACF,OAAO;AACH,YAAA,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC;SACnE;IACL
|
|
1
|
+
{"version":3,"file":"LineString.js","sources":["../../../geospatial/LineString.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Point } from './Point';\nimport { typeKey } from '../typeKey';\n\n/**\n * Represents a line string composed of two or more points.\n */\nexport class LineString {\n static readonly [typeKey] = 'LineString';\n\n coordinates!: Point[];\n\n /**\n * Creates a new LineString instance.\n * @param {Point[]} coordinates - The points that make up the line string (minimum 2 points).\n */\n constructor(coordinates: Point[]) {\n if (coordinates.length < 2) {\n throw new Error('LineString must have at least 2 points');\n }\n this.coordinates = coordinates;\n }\n\n /**\n * Converts the LineString to a GeoJSON representation.\n * @returns {object} GeoJSON representation.\n */\n toJSON(): object {\n return {\n type: 'LineString',\n coordinates: this.coordinates.map(p => [p.longitude, p.latitude])\n };\n }\n}\n"],"names":["typeKey"],"mappings":";;;;MASa,UAAU,CAAA;AACnB,IAAA,QAAiBA,eAAO,IAAI,YAAY;AAExC,IAAA,WAAW;AAMX,IAAA,WAAA,CAAY,WAAoB,EAAA;AAC5B,QAAA,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;AACxB,YAAA,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC;QAC7D;AACA,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW;IAClC;IAMA,MAAM,GAAA;QACF,OAAO;AACH,YAAA,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC;SACnE;IACL;;;"}
|