Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URI parameters deserializer #64

Merged
merged 31 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a8e2056
Move lexers to dedicated dir
surol Jul 21, 2023
1e2c3fc
Implement `scanUcTokens()` function
surol Jul 21, 2023
92cd38b
Implement `ChURIParamsLexer`
surol Jul 21, 2023
be31c39
Decode `+` as space within parameters
surol Jul 21, 2023
01bf1c8
AddIntroduce schema instance presentations
surol Jul 22, 2023
66485af
Refine `inset` compiler option
surol Jul 22, 2023
e8ca16c
Rename lexers
surol Jul 22, 2023
371318a
Require `lib` for each `UcrxClass` instance
surol Jul 22, 2023
d1232d5
Enable insets override
surol Jul 22, 2023
937286e
Combine schema presentations
surol Jul 22, 2023
af22b45
Implement raw plain text lexer
surol Jul 23, 2023
54af315
Use params charge lexer in test
surol Jul 23, 2023
7f5ba2d
Rename `.forParams()` to `.plusAsSpace()`
surol Jul 23, 2023
ac60689
URI-encoded text lexer
surol Jul 23, 2023
e5ab88e
Refine `UcdModels`
surol Jul 23, 2023
19633cf
Inset format identifiers
surol Jul 23, 2023
0d7f9d1
URI-param inset identifier
surol Jul 23, 2023
c90b76b
Rename `uriParam` presentation
surol Jul 23, 2023
a387a1a
Configure per-presentation features
surol Jul 23, 2023
15ac16d
Refine `UcrxInsetMod` interface
surol Jul 25, 2023
67cb191
Process all presentations by default
surol Jul 25, 2023
34e006a
Refine `ucInsetPlainText()` signature
surol Jul 25, 2023
f65aadf
Rename test methods
surol Jul 25, 2023
c2875be
Implement `ucInsetURIEncoded`
surol Jul 25, 2023
f594f69
Refine `ucInsetPlainText()` signature
surol Jul 25, 2023
dbbe785
Implement `ucInsetURIParams()`
surol Jul 25, 2023
f6c593d
Implement `ucInsetCharge()`
surol Jul 25, 2023
f5f225b
Mode `inset` option to `UcdModels.Entry`
surol Jul 25, 2023
19d7ef2
Split `UcdModels.Entry` types
surol Jul 25, 2023
0279b0f
Deserialization format option support
surol Jul 25, 2023
61919fd
Add missing by-tokens deserializer config
surol Jul 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/compiler/deserialization/bigint.ucrx.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ export class BigIntUcrxClass extends UcrxClass<UcrxSignature.Args, UcBigInt, UcB
}

constructor(
{ baseUcrx }: UcrxLib,
lib: UcrxLib,
schema: UcBigInt.Schema,
{ string = 'parse', number = 'parse' }: UcBigInt.Variant = {},
) {
super({
lib,
schema,
baseClass: baseUcrx,
baseClass: lib.baseUcrx,
});

UcrxCore.big.overrideIn(this, {
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/deserialization/boolean.ucrx.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ export class BooleanUcrxClass extends UcrxClass<UcrxSignature.Args, UcBoolean, U
};
}

constructor({ baseUcrx }: UcrxLib, schema: UcBoolean.Schema) {
constructor(lib: UcrxLib, schema: UcBoolean.Schema) {
super({
lib,
schema,
baseClass: baseUcrx,
baseClass: lib.baseUcrx,
});

UcrxCore.bol.overrideIn(this, {
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/deserialization/integer.ucrx.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ export class IntegerUcrxClass extends UcrxClass<UcrxSignature.Args, UcInteger, U
}

constructor(
{ baseUcrx }: UcrxLib,
lib: UcrxLib,
schema: UcInteger.Schema,
{ string = 'parse' }: UcInteger.Variant = {},
) {
super({
lib,
schema,
baseClass: baseUcrx,
baseClass: lib.baseUcrx,
});

UcrxCore.num.overrideIn(this, {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/deserialization/list.ucrx.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class ListUcrxClass<
const isMatrix = itemClass.isMemberOverridden(UcrxCore.and);

super({
lib,
schema,
typeName:
(single === 'reject' || single === 'accept' ? 'List' : 'MultiValue')
Expand Down
7 changes: 3 additions & 4 deletions src/compiler/deserialization/map.ucrx.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class MapUcrxClass<
};
}

readonly #lib: UcrxLib;
readonly #entries: EsSymbol | undefined;
readonly #extra: EsSymbol | undefined;
readonly #collector: MapUcrxClass$Collector;
Expand All @@ -64,6 +63,7 @@ export class MapUcrxClass<
variant?: UcMap.Variant,
) {
super({
lib,
typeName: MapUcrxClass$typeName(lib, schema),
schema,
baseClass: lib.baseUcrx,
Expand All @@ -72,8 +72,6 @@ export class MapUcrxClass<
},
});

this.#lib = lib;

this.#entries = this.#declareEntries();
this.#extra = this.#declareExtra();
this.#collector = this.#declareCollector(variant);
Expand Down Expand Up @@ -411,7 +409,7 @@ export class MapUcrxClass<
}

entryUcrxFor(key: string | null, schema: UcSchema): UcrxClass {
const entryClass = MapUcrxEntry.ucrxClass(this.#lib, this.schema, key, schema);
const entryClass = MapUcrxEntry.ucrxClass(this.lib, this.schema, key, schema);

return this.#collector.rxs ? entryClass.associate(MultiEntryUcrxClass$associate) : entryClass;
}
Expand Down Expand Up @@ -517,6 +515,7 @@ class MultiEntryUcrxClass<

constructor(baseClass: UcrxClass<TArgs, T, TSchema>) {
super({
lib: baseClass.lib,
schema: baseClass.schema,
baseClass,
typeName: `${baseClass.typeName}$Entry`,
Expand Down
1 change: 1 addition & 0 deletions src/compiler/deserialization/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export * from './ucd-handler-feature.js';
export * from './ucd-lib.js';
export * from './ucd-models.js';
export * from './ucd-support-defaults.js';
export * from './ucd-support-inset.js';
export * from './ucd-support-non-finite.js';
export * from './ucd-support-primitives.js';
export * from './unknown.ucrx.class.js';
9 changes: 3 additions & 6 deletions src/compiler/deserialization/number.ucrx.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ export class NumberUcrxClass extends UcrxClass<UcrxSignature.Args, UcNumber, UcN
};
}

constructor(
{ baseUcrx }: UcrxLib,
schema: UcNumber.Schema,
{ string = 'parse' }: UcNumber.Variant = {},
) {
constructor(lib: UcrxLib, schema: UcNumber.Schema, { string = 'parse' }: UcNumber.Variant = {}) {
super({
lib,
schema,
baseClass: baseUcrx,
baseClass: lib.baseUcrx,
});

UcrxCore.num.overrideIn(this, {
Expand Down
9 changes: 3 additions & 6 deletions src/compiler/deserialization/string.ucrx.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ export class StringUcrxClass extends UcrxClass<UcrxSignature.Args, UcString, UcS
};
}

constructor(
{ baseUcrx }: UcrxLib,
schema: UcString.Schema,
{ raw = 'escape' }: UcString.Variant = {},
) {
constructor(lib: UcrxLib, schema: UcString.Schema, { raw = 'escape' }: UcString.Variant = {}) {
super({
lib,
schema,
baseClass: baseUcrx,
baseClass: lib.baseUcrx,
});
if (raw !== 'parse') {
UcrxCore.raw.overrideIn(this, {
Expand Down
30 changes: 15 additions & 15 deletions src/compiler/deserialization/ucd-compiler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from '@jest/globals';
import { EsBundleFormat } from 'esgen';
import { SPEC_MODULE } from '../../impl/module-names.js';
import { UcModel, UcSchema } from '../../schema/uc-schema.js';
import { UcSchema } from '../../schema/uc-schema.js';
import { ucdSupportTimestampFormat } from '../../spec/timestamp.format.js';
import { UcdCompiler } from './ucd-compiler.js';
import { ucdSupportDefaults } from './ucd-support-defaults.js';
Expand All @@ -11,7 +11,7 @@ describe('UcdCompiler', () => {
it('enables feature in object form', async () => {
const compiler = new UcdCompiler({
models: {
readTimestamp: ['sync', Number],
readTimestamp: { model: Number, mode: 'sync' },
},
features: [
{
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('UcdCompiler', () => {
};
const compiler = new UcdCompiler({
models: {
readTimestamp: ['sync', schema],
readTimestamp: { model: schema, mode: 'sync' },
},
});

Expand All @@ -88,7 +88,7 @@ describe('UcdCompiler', () => {
};
const compiler = new UcdCompiler({
models: {
readTimestamp: ['sync', schema],
readTimestamp: { model: schema, mode: 'sync' },
},
});

Expand All @@ -109,7 +109,7 @@ describe('UcdCompiler', () => {
};
const compiler = new UcdCompiler({
models: {
readTimestamp: ['sync', schema],
readTimestamp: { model: schema, mode: 'sync' },
},
});

Expand All @@ -130,8 +130,8 @@ describe('UcdCompiler', () => {
};

await expect(
new UcdCompiler<{ readTimestamp: UcModel<number> }>({
models: { readTimestamp: schema },
new UcdCompiler({
models: { readTimestamp: { model: schema } },
}).bootstrap(),
).rejects.toThrow(
new ReferenceError(
Expand All @@ -151,8 +151,8 @@ describe('UcdCompiler', () => {
};

await expect(
new UcdCompiler<{ readTimestamp: UcModel<number> }>({
models: { readTimestamp: schema },
new UcdCompiler({
models: { readTimestamp: { model: schema } },
}).bootstrap(),
).rejects.toThrow(
new ReferenceError(
Expand All @@ -166,7 +166,7 @@ describe('UcdCompiler', () => {
describe('ES2015', () => {
it('compiles async module', async () => {
const compiler = new UcdCompiler({
models: { readValue: ['async', Number] },
models: { readValue: { model: Number, mode: 'async' } },
});
const text = await compiler.generate();

Expand All @@ -191,7 +191,7 @@ export async function readValue(
});
it('compiles sync module', async () => {
const compiler = new UcdCompiler({
models: { readValue: ['sync', Number] },
models: { readValue: { model: Number, mode: 'sync' } },
});
const text = await compiler.generate();

Expand All @@ -215,7 +215,7 @@ export function readValue(
});
it('compiles universal module', async () => {
const compiler = new UcdCompiler({
models: { readValue: Number },
models: { readValue: { model: Number } },
});
const text = await compiler.generate();

Expand Down Expand Up @@ -243,7 +243,7 @@ export function readValue(
describe('IIFE', () => {
it('creates async factory', async () => {
const compiler = new UcdCompiler({
models: { readValue: ['async', Number] },
models: { readValue: { model: Number, mode: 'async' } },
});
const text = await compiler.generate({ format: EsBundleFormat.IIFE });

Expand All @@ -268,7 +268,7 @@ export function readValue(
});
it('creates sync factory', async () => {
const compiler = new UcdCompiler({
models: { readValue: ['sync', Number] },
models: { readValue: { model: Number, mode: 'sync' } },
});
const text = await compiler.generate({ format: EsBundleFormat.IIFE });

Expand All @@ -293,7 +293,7 @@ export function readValue(
});
it('creates universal factory', async () => {
const compiler = new UcdCompiler({
models: { readValue: Number },
models: { readValue: { model: Number } },
});
const text = await compiler.generate({ format: EsBundleFormat.IIFE });

Expand Down
23 changes: 10 additions & 13 deletions src/compiler/deserialization/ucd-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ import {
esline,
} from 'esgen';
import { capitalize } from 'httongue';
import { UcPresentationName } from '../../schema/uc-presentations.js';
import { UcSchema } from '../../schema/uc-schema.js';
import { UcdHandlerRegistry } from '../impl/ucd-handler-registry.js';
import { UccConfig } from '../processor/ucc-config.js';
import { UccFeature } from '../processor/ucc-feature.js';
import { UcrxLib } from '../rx/ucrx-lib.js';
import { UcrxProcessor } from '../rx/ucrx-processor.js';
import { UcrxClass, UcrxSignature } from '../rx/ucrx.class.js';
import { UcdFunction } from './ucd-function.js';
import { UcdHandlerFeature } from './ucd-handler-feature.js';
import { UcdLib } from './ucd-lib.js';
import { UcdExports, UcdModels, isUcdModelConfig } from './ucd-models.js';
import { UcdExports, UcdModels } from './ucd-models.js';
import { ucdSupportDefaults } from './ucd-support-defaults.js';

/**
Expand Down Expand Up @@ -53,11 +53,12 @@ export class UcdCompiler<
* @param options - Compiler options.
*/
constructor(options: UcdCompiler.Options<TModels>) {
const { models, validate = true, features } = options;
const { models, presentations, validate = true, features } = options;

super({
names: validate ? ['validator', 'deserializer'] : ['deserializer'],
models: Object.values(models).map(entry => (isUcdModelConfig(entry) ? entry[1] : entry)),
processors: validate ? ['validator', 'deserializer'] : ['deserializer'],
presentations,
models: Object.values(models).map(({ model }) => model),
features,
});

Expand Down Expand Up @@ -92,7 +93,7 @@ export class UcdCompiler<

// Stop registering default handlers.
// Start registering custom ones.
defaultConfig.configure();
defaultConfig.configure(undefined, {});

this.#entities.makeDefault();
this.#formats.makeDefault();
Expand Down Expand Up @@ -343,19 +344,15 @@ export class UcdCompiler<
export namespace UcdCompiler {
export type Any = UcdCompiler<UcdModels>;

export interface Options<out TModels extends UcdModels> extends Omit<UcrxLib.Options, 'methods'> {
export interface Options<out TModels extends UcdModels = UcdModels>
extends Omit<UcrxLib.Options, 'methods'> {
readonly models: TModels;
readonly presentations?: UcPresentationName | UcPresentationName[] | undefined;
readonly validate?: boolean | undefined;
readonly features?:
| UccFeature<UcdCompiler.Any>
| readonly UccFeature<UcdCompiler.Any>[]
| undefined;
readonly inset?: EsSnippet | undefined;
readonly exportDefaults?: boolean | undefined;

createDeserializer?<T, TSchema extends UcSchema<T>>(
this: void,
options: UcdFunction.Options<T, TSchema>,
): UcdFunction<T, TSchema>;
}
}
Loading