UNPKG

@mathrunet/masamune

Version:

Manages packages for the server portion (NodeJS) of the Masamune framework.

584 lines 15.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ModelRefBase = exports.ModelVectorValue = exports.ModelGeoValue = exports.ModelToken = exports.ModelSearch = exports.ModelVideoUri = exports.ModelImageUri = exports.ModelUri = exports.ModelLocalizedLocaleVaue = exports.ModelLocalizedValue = exports.ModelLocale = exports.ModelTimeRange = exports.ModelDateRange = exports.ModelTimestampRange = exports.ModelTime = exports.ModelDate = exports.ModelTimestamp = exports.ModelCounter = exports.ModelServerCommandBase = exports.ModelFieldValue = void 0; /** * Class for generating values for `ModelFieldValue` in katana_model. * * katana_modelの`ModelFieldValue`用の値を生成するためのクラス。 */ class ModelFieldValue { constructor(type, source) { this["@type"] = type; this["@source"] = source ?? "user"; } "@type"; "@source"; } exports.ModelFieldValue = ModelFieldValue; /** * ModelServerCommandBase interface. * * katana_modelの`ModelServerCommandBase`用のインターフェース。 */ class ModelServerCommandBase extends ModelFieldValue { constructor({ command, publicParameters, privateParameters, source }) { super("ModelServerCommandBase", source); this["@command"] = command; this["@public"] = publicParameters; this["@private"] = privateParameters; } "@command"; "@public"; "@private"; /** * Get the value of the command. * * コマンドの値を取得します。 * * @returns The value of the command. */ value() { return this["@command"]; } } exports.ModelServerCommandBase = ModelServerCommandBase; /** * ModelCounter interface. * * katana_modelの`ModelCounter`用のインターフェース。 */ class ModelCounter extends ModelFieldValue { constructor(value, increment, source) { super("ModelCounter", source); this["@value"] = value; this["@increment"] = increment ?? 0; } "@increment"; "@value"; /** * Get the value of the counter. * * カウンターの値を取得します。 * * @returns The value of the counter. */ value() { return this["@value"] + this["@increment"]; } } exports.ModelCounter = ModelCounter; /** * ModelTimestamp interface. * * katana_modelの`ModelTimestamp`用のインターフェース。 */ class ModelTimestamp extends ModelFieldValue { constructor(time, source) { super("ModelTimestamp", source); // Store in microseconds for consistency with value() and Firestore converters this["@time"] = (time?.getTime() ?? Date.now()) * 1000; } "@time"; /** * Get the value of the timestamp. * * タイムスタンプの値を取得します。 * * @returns */ value() { return new Date(this["@time"] / 1000.0); } } exports.ModelTimestamp = ModelTimestamp; /** * ModelDate interface. * * katana_modelの`ModelDate`用のインターフェース。 */ class ModelDate extends ModelFieldValue { constructor(date, source) { super("ModelDate", source); date ??= new Date(); date = new Date(date.getFullYear(), date.getMonth(), date.getDate()); this["@time"] = date.getTime(); } "@time"; /** * Get the value of the timestamp. * * タイムスタンプの値を取得します。 * * @returns */ value() { return new Date(this["@time"] / 1000.0); } } exports.ModelDate = ModelDate; /** * ModelTime interface. * * katana_modelの`ModelTime`用のインターフェース。 */ class ModelTime extends ModelFieldValue { constructor(time, source) { super("ModelTime", source); time ??= new Date(); const now = new Date(); time = new Date(now.getFullYear(), now.getMonth(), now.getDate(), time.getHours(), time.getMinutes(), time.getSeconds(), time.getMilliseconds()); this["@time"] = time.getTime(); } "@time"; /** * Get the value of the timestamp. * * タイムスタンプの値を取得します。 * * @returns */ value() { return new Date(this["@time"] / 1000.0); } } exports.ModelTime = ModelTime; /** * ModelTimestampRange interface. * * katana_modelの`ModelTimestampRange`用のインターフェース。 */ class ModelTimestampRange extends ModelFieldValue { constructor(start, end, source) { super("ModelTimestampRange", source); start ??= new Date(); end ??= new Date(); if (start > end) { const temp = start; start = end; end = temp; } this["@start"] = start.getTime(); this["@end"] = end.getTime(); } "@start"; "@end"; /** * Get the value of the timestamp. * * タイムスタンプの値を取得します。 * * @returns */ value() { return { start: new Date(this["@start"] / 1000.0), end: new Date(this["@end"] / 1000.0), }; } } exports.ModelTimestampRange = ModelTimestampRange; /** * ModelDateRange interface. * * katana_modelの`ModelDateRange`用のインターフェース。 */ class ModelDateRange extends ModelFieldValue { constructor(start, end, source) { super("ModelDateRange", source); start ??= new Date(); end ??= new Date(); start = new Date(start.getFullYear(), start.getMonth(), start.getDate()); end = new Date(end.getFullYear(), end.getMonth(), end.getDate()); if (start > end) { const temp = start; start = end; end = temp; } this["@start"] = start.getTime(); this["@end"] = end.getTime(); } "@start"; "@end"; /** * Get the value of the timestamp. * * タイムスタンプの値を取得します。 * * @returns */ value() { return { start: new Date(this["@start"] / 1000.0), end: new Date(this["@end"] / 1000.0), }; } } exports.ModelDateRange = ModelDateRange; /** * ModelTimeRange interface. * * katana_modelの`ModelTimeRange`用のインターフェース。 */ class ModelTimeRange extends ModelFieldValue { constructor(start, end, source) { super("ModelTimeRange", source); const now = new Date(); start ??= new Date(); end ??= new Date(); start = new Date(now.getFullYear(), now.getMonth(), now.getDate(), start.getHours(), start.getMinutes(), start.getSeconds(), start.getMilliseconds()); end = new Date(now.getFullYear(), now.getMonth(), now.getDate(), end.getHours(), end.getMinutes(), end.getSeconds(), end.getMilliseconds()); if (start > end) { const temp = start; start = end; end = temp; } this["@start"] = start.getTime(); this["@end"] = end.getTime(); } "@start"; "@end"; /** * Get the value of the timestamp. * * タイムスタンプの値を取得します。 * * @returns */ value() { return { start: new Date(this["@start"] / 1000.0), end: new Date(this["@end"] / 1000.0), }; } } exports.ModelTimeRange = ModelTimeRange; /** * ModelLocale interface. * * katana_modelの`ModelLocale`用のインターフェース。 */ class ModelLocale extends ModelFieldValue { constructor(language, country, source) { super("ModelLocale", source); this["@language"] = language; this["@country"] = country; } "@language"; "@country"; /** * Get the value of the locale. * * ロケールの値を取得します。 * * @returns The value of the locale. */ value() { if (this["@country"]) { return `${this["@language"]}_${this["@country"]}`; } return this["@language"]; } } exports.ModelLocale = ModelLocale; /** * ModelLocalizedValue interface. * * katana_modelの`ModelLocalizedValue`用のインターフェース。 */ class ModelLocalizedValue extends ModelFieldValue { constructor(localized, source) { super("ModelLocalizedValue", source); this["@localized"] = localized; } "@localized"; /** * Get the value of the localized value. * * ローカライズされた値の値を取得します。 * * @returns The value of the localized value. */ value() { return this["@localized"]; } /** * Get the value of the localized value for the specified locale. * * 指定されたロケールのローカライズされた値の値を取得します。 * * @param locale The locale to get the value for. * @returns The value of the localized value for the specified locale. */ get(locale) { return this["@localized"].find((e) => e.language === locale) ?? null; } } exports.ModelLocalizedValue = ModelLocalizedValue; /** * The value of ModelLocalizedValue. * * ModelLocalizedValueの値。 */ class ModelLocalizedLocaleVaue { constructor({ language, country, value }) { this.language = language; this.country = country; this.value = value; } language; country; value; } exports.ModelLocalizedLocaleVaue = ModelLocalizedLocaleVaue; /** * ModelUri interface. * * katana_modelの`ModelUri`用のインターフェース。 */ class ModelUri extends ModelFieldValue { constructor(uri, source) { super("ModelUri", source); this["@uri"] = uri; } "@uri"; /** * Get the value of the uri. * * URIの値を取得します。 * * @returns The value of the uri. */ value() { return this["@uri"]; } } exports.ModelUri = ModelUri; /** * ModelImageUri interface. * * katana_modelの`ModelImageUri`用のインターフェース。 */ class ModelImageUri extends ModelFieldValue { constructor(uri, source) { super("ModelImageUri", source); this["@uri"] = uri; } "@uri"; /** * Get the value of the uri. * * URIの値を取得します。 * * @returns The value of the uri. */ value() { return this["@uri"]; } } exports.ModelImageUri = ModelImageUri; /** * ModelVideoUri interface. * * katana_modelの`ModelVideoUri`用のインターフェース。 */ class ModelVideoUri extends ModelFieldValue { constructor(uri, source) { super("ModelVideoUri", source); this["@uri"] = uri; } "@uri"; /** * Get the value of the uri. * * URIの値を取得します。 * * @returns The value of the uri. */ value() { return this["@uri"]; } } exports.ModelVideoUri = ModelVideoUri; /** * ModelSearch interface. * * katana_modelの`ModelSearch`用のインターフェース。 */ class ModelSearch extends ModelFieldValue { constructor(list, source) { super("ModelSearch", source); this["@list"] = list; } "@list"; /** * Get the value of the search. * * 検索の値を取得します。 * * @returns The value of the search. */ value() { return this["@list"]; } } exports.ModelSearch = ModelSearch; /** * ModelToken interface. * * katana_modelの`ModelToken`用のインターフェース。 */ class ModelToken extends ModelFieldValue { constructor(list, source) { super("ModelToken", source); this["@list"] = list; } "@list"; /** * Get the value of the token. * * トークンの値を取得します。 * * @returns The value of the token. */ value() { return this["@list"]; } } exports.ModelToken = ModelToken; /** * ModelGeoValue interface. * * katana_modelの`ModelGeoValue`用のインターフェース。 */ class ModelGeoValue extends ModelFieldValue { constructor(latitude, longitude, source) { super("ModelGeoValue", source); this["@latitude"] = latitude; this["@longitude"] = longitude; } "@latitude"; "@longitude"; /** * Get the value of the geo value. * * 地理値の値を取得します。 * * @returns The value of the geo value. */ value() { return { latitude: this["@latitude"], longitude: this["@longitude"] }; } } exports.ModelGeoValue = ModelGeoValue; /** * ModelVectorValue interface. * * katana_modelの`ModelVectorValue`用のインターフェース。 */ class ModelVectorValue extends ModelFieldValue { constructor(vector, source) { super("ModelVectorValue", source); this["@vector"] = vector; } "@vector"; /** * Get the value of the vector value. * * ベクトル値の値を取得します。 * * @returns The value of the vector value. */ value() { return this["@vector"]; } } exports.ModelVectorValue = ModelVectorValue; /** * ModelRefBase interface. * * katana_modelの`ModelRefBase`用のインターフェース。 */ class ModelRefBase extends ModelFieldValue { constructor(ref, doc, source) { super("ModelRefBase", source); this["@ref"] = ref; this["@doc"] = doc; } "@ref"; "@doc"; /** * Get the value of the ref. * * リファレンスの値を取得します。 * * @returns The value of the ref. */ value() { return this["@ref"]; } /** * Load the document. * * ドキュメントを読み込みます。 * * @returns The value of the ref. */ async load() { const res = await this["@doc"]?.load(); if (!res) { throw new Error("Failed to load document"); } return res; } /** * Save the document. * * ドキュメントを保存します。 * * @param data The data to save. * @param options The options to save. * @returns The value of the ref. */ async save(data, options) { await this["@doc"]?.save(data, options); } /** * Delete the document. * * ドキュメントを削除します。 * * @returns The value of the ref. */ async delete() { await this["@doc"]?.delete(); } /** * Get the id of the ref. * * リファレンスのIDを取得します。 * * @returns The id of the ref. */ get id() { const doc = this["@doc"]; if (!doc) { return this["@ref"]?.split("/").pop() ?? ""; } return doc.id; } /** * Get the ref of the document. * * ドキュメントのリファレンスを取得します。 * * @returns The ref of the document. */ get ref() { return this["@doc"]; } } exports.ModelRefBase = ModelRefBase; //# sourceMappingURL=model_field_value.js.map