Comparing version 9.0.0 to 9.1.0
@@ -1,3 +0,3 @@ | ||
import { existsSync, readFileSync, writeFileSync } from "fs"; | ||
import { resolve } from "path"; | ||
import { existsSync, readFileSync, writeFileSync } from "node:fs"; | ||
import { resolve } from "node:path"; | ||
import { cwd, resolveFileOrDir } from "../utils/fs.js"; | ||
@@ -4,0 +4,0 @@ |
{ | ||
"name": "hybrids", | ||
"version": "9.0.0", | ||
"version": "9.1.0", | ||
"description": "A JavaScript framework for creating fully-featured web applications, components libraries, and single web components with unique declarative and functional architecture", | ||
@@ -63,3 +63,2 @@ "type": "module", | ||
"karma-webkit-launcher": "^2.1.0", | ||
"log4js": "^6.2.1", | ||
"playwright": "^1.41.2", | ||
@@ -66,0 +65,0 @@ "prettier": "^3.1.1", |
@@ -19,3 +19,3 @@ | ||
* **Localization** with automatic translation of the templates content | ||
* **Hot Module Replacement** out of the box support and other DX features | ||
* **Hot Module Replacement** support without any additional configuration | ||
@@ -22,0 +22,0 @@ ### Documentation |
@@ -8,3 +8,2 @@ import * as cache from "./cache.js"; | ||
const stales = new WeakMap(); | ||
const refs = new WeakSet(); | ||
@@ -347,2 +346,5 @@ function resolve(config, model, lastModel) { | ||
const refs = new WeakSet(); | ||
const records = new WeakMap(); | ||
function ref(fn) { | ||
@@ -357,2 +359,17 @@ if (typeof fn !== "function") { | ||
function record(value) { | ||
if (value === undefined || value === null) { | ||
throw TypeError(`The value must be defined: ${value}`); | ||
} | ||
if (!refs.has(value) && typeof value === "function") { | ||
throw TypeError(`A function is not supported as the value of the record`); | ||
} | ||
const model = Object.freeze({}); | ||
records.set(model, value); | ||
return model; | ||
} | ||
const validationMap = new WeakMap(); | ||
@@ -362,2 +379,17 @@ function resolveKey(Model, key, config) { | ||
if (refs.has(defaultValue)) defaultValue = defaultValue(); | ||
if (records.has(defaultValue)) { | ||
const value = records.get(defaultValue); | ||
if (typeof value === "function") { | ||
throw TypeError( | ||
`A function is not supported as the value of the record for '${key}' property`, | ||
); | ||
} | ||
return { | ||
defaultValue: { id: true, value }, | ||
type: "record", | ||
}; | ||
} | ||
let type = typeof defaultValue; | ||
@@ -693,2 +725,37 @@ | ||
} | ||
case "record": { | ||
const localConfig = bootstrap(defaultValue, true); | ||
return (model, data, lastModel) => { | ||
const record = data[key]; | ||
const result = | ||
lastModel && lastModel[key] ? { ...lastModel[key] } : {}; | ||
if (record === null || record === undefined) { | ||
model[key] = {}; | ||
return; | ||
} | ||
for (const id of Object.keys(record)) { | ||
if (record[id] === null || record[id] === undefined) { | ||
delete result[id]; | ||
continue; | ||
} | ||
const item = localConfig.create( | ||
{ id, value: record[id] }, | ||
result[id], | ||
); | ||
Object.defineProperty(result, id, { | ||
get() { | ||
return cache.get(this, id, () => item.value); | ||
}, | ||
enumerable: true, | ||
}); | ||
} | ||
model[key] = result; | ||
}; | ||
} | ||
// eslint-disable-next-line no-fallthrough | ||
@@ -1666,3 +1733,4 @@ default: { | ||
ref, | ||
record, | ||
}), | ||
); |
@@ -175,2 +175,4 @@ const hasAdoptedStylesheets = !!( | ||
landscape: "orientation: landscape", | ||
hover: "hover: hover", | ||
"any-hover": "any-hover: hover", | ||
}; | ||
@@ -177,0 +179,0 @@ |
@@ -140,17 +140,16 @@ export type Property<E, V> = | ||
export type NestedArrayModel<T> = NonNullable<Unarray<T>> extends | ||
| string | ||
| String | ||
? T | string[] | [String | StringConstructor] | ||
: NonNullable<Unarray<T>> extends number | Number | ||
? T | number[] | [Number | NumberConstructor] | ||
: NonNullable<Unarray<T>> extends boolean | Boolean | ||
? T | boolean[] | [Boolean | BooleanConstructor] | ||
: NonNullable<Unarray<T>> extends EnumerableInstance | ||
? | ||
| [Model<NonNullable<Unarray<T>>>] | ||
| [Model<NonNullable<Unarray<T>>>, { loose?: boolean }] | ||
: NonNullable<Unarray<T>> extends NonArrayObject | ||
? T | ||
: never; | ||
export type NestedArrayModel<T> = | ||
NonNullable<Unarray<T>> extends string | String | ||
? T | string[] | [String | StringConstructor] | ||
: NonNullable<Unarray<T>> extends number | Number | ||
? T | number[] | [Number | NumberConstructor] | ||
: NonNullable<Unarray<T>> extends boolean | Boolean | ||
? T | boolean[] | [Boolean | BooleanConstructor] | ||
: NonNullable<Unarray<T>> extends EnumerableInstance | ||
? | ||
| [Model<NonNullable<Unarray<T>>>] | ||
| [Model<NonNullable<Unarray<T>>>, { loose?: boolean }] | ||
: NonNullable<Unarray<T>> extends NonArrayObject | ||
? T | ||
: never; | ||
@@ -286,4 +285,7 @@ export type ModelIdentifier = | ||
function ref<T>(fn: () => T): T; | ||
function ref<T>(fn: () => T): () => T; | ||
function record<V>(value: V): Record<string, V>; | ||
function record<V extends () => {}>(value: V): Record<string, ReturnType<V>>; | ||
interface ValidateFunction<M extends ModelInstance, T> { | ||
@@ -290,0 +292,0 @@ (value: T, key: string, model: M): string | boolean | void; |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
209854
15
6676
0