Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bscotch/cl2-string-server-shared

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bscotch/cl2-string-server-shared - npm Package Compare versions

Comparing version 0.5.2 to 0.6.0

dist/types.issues.d.ts

26

dist/client.d.ts
/// <reference types="node" />
/// <reference types="node" />
import { BaseError } from './errors.js';
import { Annotation, AnnotationPatch, Branch, BranchPatch, Comment, CommentPatch, CommentPost, GlossaryGet, GlossaryTermPatch, GlossaryTermPost, GlossaryTermWithId, ImageSearch, StringEditsGet, type CommittedString, type ImageMetadata, type ImagePatch, type PatchUser, type PostedUser, type StringPatch, type StringsGet, type StringsPut } from './types.js';
import { Annotation, AnnotationPatch, Branch, BranchPatch, Comment, CommentPatch, CommentPost, GlossaryGet, GlossaryTermPatch, GlossaryTermPost, GlossaryTermWithId, ImageSearch, Project, ProjectPatch, StringEditsGet, StringLocalized, TranslationIssue, TranslationIssuePatch, type ImageMetadata, type ImagePatch, type PatchUser, type PostedUser, type StringCommitted, type StringPatch, type StringsGet, type StringsPut } from './types.js';
export declare class Client {

@@ -39,8 +39,20 @@ readonly options: {

getXliff(projectId: string, branchId: string): Promise<string>;
updateString(projectId: string, branchId: string, commitNumber: number, stringId: string, update: StringPatch): Promise<CommittedString>;
updateTranslation(xliffContent: string): Promise<void>;
updateString(projectId: string, branchId: string, commitNumber: number, stringId: string, update: StringPatch): Promise<StringCommitted>;
commitStrings(projectId: string, strings: StringsPut): Promise<void>;
listStrings(projectId: string, branchId: string): Promise<StringsGet>;
/**
* Find a specific string. By default returns
* all variants across branches, unless a specific
* branch is specified.'
*/
findString(projectId: string, stringId: string, branchId?: string, options?: {
includeDeleted?: boolean;
}): Promise<StringLocalized[]>;
listStrings(projectId: string, branchId: string, options?: {
includeTranslations?: boolean;
}): Promise<StringsGet>;
listStringEdits(projectId: string, branchId: string): Promise<StringEditsGet>;
listProjects(): Promise<string[]>;
getProject(projectId: string): Promise<string>;
listProjects(): Promise<Project[]>;
getProject(projectId: string): Promise<Project>;
updateProject(projectId: string, patch: ProjectPatch): Promise<Project>;
listBranches(projectId: string): Promise<Branch[]>;

@@ -57,3 +69,3 @@ getBranch(projectId: string, branchId: string): Promise<Branch>;

/** Create or update an image */
uploadImage(name: string, data: Buffer): Promise<ImageMetadata>;
uploadImage(name: string, data: Buffer | ArrayBuffer): Promise<ImageMetadata>;
updateImageMetadata(name: string, data: ImagePatch): Promise<ImageMetadata>;

@@ -69,2 +81,4 @@ downloadImage(name: string): Promise<ArrayBuffer>;

deleteEntityComments(entity: string): Promise<void>;
listIssues(projectId: string, branchId?: string): Promise<TranslationIssue[]>;
updateIssue(projectId: string, branchId: string, stringId: string, lang: string, code: string, patch: TranslationIssuePatch): Promise<TranslationIssuePatch>;
}

@@ -71,0 +85,0 @@ export declare class FetchError extends BaseError {

import { BaseError, assert } from './errors.js';
import { annotationPatchSchema, branchIdSchema, commentEntitySchema, commentIdSchema, commentPatchSchema, commentPostSchema, glossaryGetSchema, glossaryTermPatchSchema, glossaryTermPostSchema, glossaryTermWithIdSchema, imageNameSchema, imagePatchSchema, imageSearchSchema, mongoIdSchema, patchBranchSchema, patchUserSchema, postedUserSchema, projectIdSchema, stringIdSchema, stringsPutSchema, usernameSchema, } from './types.js';
import { annotationPatchSchema, branchIdSchema, branchPatchSchema, commentEntitySchema, commentIdSchema, commentPatchSchema, commentPostSchema, glossaryGetSchema, glossaryTermPatchSchema, glossaryTermPostSchema, glossaryTermWithIdSchema, imageNameSchema, imagePatchSchema, imageSearchSchema, mongoIdSchema, patchUserSchema, postedUserSchema, projectIdSchema, projectPatchSchema, stringIdSchema, stringsPutSchema, usernameSchema, } from './types.js';
export class Client {

@@ -33,8 +33,7 @@ options;

}
let body;
let body = options?.body;
if (isBuffer(options?.body) || options?.body instanceof ArrayBuffer) {
body = options.body;
headers['Content-Type'] ||= 'application/octet-stream';
}
else if (options?.body) {
else if (typeof options?.body === 'object') {
body = JSON.stringify(options.body);

@@ -69,2 +68,3 @@ headers['Content-Type'] ||= 'application/json';

}
//#region USERS
/**

@@ -135,2 +135,3 @@ * Log in to the server, which will set a cookie for future requests.

}
//#endregion USERS
async getXliff(projectId, branchId) {

@@ -144,2 +145,9 @@ projectId = projectIdSchema.parse(projectId);

}
async updateTranslation(xliffContent) {
await this.request('POST', `/api/translations`, {
body: xliffContent,
contentType: 'application/xliff+xml',
assertStatus: 204,
});
}
async updateString(projectId, branchId, commitNumber, stringId, update) {

@@ -163,6 +171,20 @@ projectId = projectIdSchema.parse(projectId);

}
async listStrings(projectId, branchId) {
/**
* Find a specific string. By default returns
* all variants across branches, unless a specific
* branch is specified.'
*/
async findString(projectId, stringId, branchId, options) {
projectId = projectIdSchema.parse(projectId);
branchId = branchId ? branchIdSchema.parse(branchId) : '@all';
stringId = stringIdSchema.parse(stringId);
const result = (await this.request('GET', `/api/projects/${projectId}/branches/${branchId}/strings/${encodeURIComponent(stringId)}?includeDeleted=${options?.includeDeleted ? 'true' : 'false'}`, {
assertStatus: 200,
})).body;
return result.variants;
}
async listStrings(projectId, branchId, options) {
projectId = projectIdSchema.parse(projectId);
branchId = branchIdSchema.parse(branchId);
const strings = (await this.request('GET', `/api/projects/${projectId}/branches/${branchId}/strings`, {
const strings = (await this.request('GET', `/api/projects/${projectId}/branches/${branchId}/strings?translations=${options?.includeTranslations ? 'true' : 'false'}`, {
assertStatus: 200,

@@ -183,3 +205,3 @@ })).body;

assertStatus: 200,
})).body;
})).body.projects;
return projects;

@@ -194,2 +216,11 @@ }

}
async updateProject(projectId, patch) {
projectId = projectIdSchema.parse(projectId);
patch = projectPatchSchema.parse(patch);
const project = (await this.request('PATCH', `/api/projects/${projectId}`, {
body: patch,
assertStatus: 200,
})).body;
return project;
}
async listBranches(projectId) {

@@ -216,3 +247,3 @@ projectId = projectIdSchema.parse(projectId);

assertStatus: 200,
body: patchBranchSchema.parse(patch),
body: branchPatchSchema.parse(patch),
})).body;

@@ -273,3 +304,3 @@ return branch;

name = imageNameSchema.parse(name);
assert(isBuffer(data), 'data must be a Buffer');
assert(isBuffer(data) || data instanceof ArrayBuffer, 'data must be a Buffer');
const image = (await this.request('PUT', `/api/images/${name}`, {

@@ -368,2 +399,17 @@ body: data,

}
//#endregion COMMENTS
//#region ISSUES
async listIssues(projectId, branchId) {
const issues = (await this.request('GET', `/api/projects/${projectId}/branches/${branchId || '@all'}/issues`, {
assertStatus: 200,
})).body;
return issues.issues;
}
async updateIssue(projectId, branchId, stringId, lang, code, patch) {
const updated = (await this.request('PATCH', `/api/projects/${projectId}/branches/${branchId}/issues/${encodeURIComponent(stringId)}/${lang}/${code}`, {
body: patch,
assertStatus: 200,
})).body;
return updated;
}
}

@@ -370,0 +416,0 @@ export class FetchError extends BaseError {

@@ -32,2 +32,9 @@ import nspell from 'nspell';

parse(text: string): Substring<string>[];
findTermById(termId: string): {
text: string;
lower: string;
insensitive: boolean;
termId: string;
definition?: string | null | undefined;
} | undefined;
onNewTerm(callback: (term: GlossaryTermWithId) => void): () => boolean;

@@ -40,2 +47,4 @@ onTermRemoved(callback: (term: GlossaryTermWithId) => void): () => boolean;

addTerm(text: string, definition?: string, insensitive?: boolean): Promise<GlossaryTermWithId>;
addTerm(term: GlossaryTermWithId): Promise<GlossaryTermWithId>;
updateTerm(term: GlossaryTermWithId): Promise<void>;
updateTerm(termId: string, update: {

@@ -46,3 +55,5 @@ text: string;

}): Promise<void>;
removeTerm(textId: string): Promise<void>;
removeTerm(textId: string, options?: {
localOnly?: boolean;
}): Promise<void>;
protected addTermToDictionary(term: GlossaryTermWithId): void;

@@ -49,0 +60,0 @@ protected removeTermFromDictionary(term: GlossaryTermWithId): void;

@@ -19,2 +19,5 @@ import nspell from 'nspell';

}
findTermById(termId) {
return this.termsById.get(termId);
}
onNewTerm(callback) {

@@ -32,2 +35,10 @@ this.listeners.newTerm.add(callback);

};
const findTerm = (sub) => {
const lower = sub.substr.toLowerCase();
let term = this.termsByLowerText.get(lower);
if (!term && lower.endsWith('s')) {
term = this.termsByLowerText.get(lower.slice(0, -1));
}
return term;
};
if (!text) {

@@ -40,9 +51,10 @@ return sortTerms([...this.termsById.values()]);

.map((sub) => {
if (!sub.isWord ||
uniqueTerms.has(sub.substr) ||
!this.termsByLowerText.has(sub.substr.toLowerCase())) {
if (!sub.isWord)
return;
const term = findTerm(sub);
if (!term || uniqueTerms.has(term.termId)) {
return;
}
uniqueTerms.add(sub.substr);
return this.termsByLowerText.get(sub.substr.toLowerCase());
uniqueTerms.add(term.termId);
return term;
})

@@ -54,9 +66,16 @@ .filter(Boolean);

let value = word.substr;
if (value.match(/in'$/)) {
if (value.match(/in['’]$/u)) {
// Then it's probably folksy contraction
value = value.replace(/in'$/, 'ing');
value = value.replace(/in['’]$/u, 'ing');
}
const valid = !word.isWord ||
this.checker.correct(value) ||
this.checker.correct(value.toLowerCase());
const check = (value) => {
const isValid = this.checker.correct(value) ||
this.checker.correct(value.toLowerCase());
return isValid;
};
let valid = !word.isWord || check(value);
if (!valid && word.isWord && value.match(/s$/)) {
// Try removing the trailing 's' to see if it's a plural
valid = check(value.slice(0, -1));
}
return {

@@ -70,12 +89,14 @@ ...word,

}
async addTerm(text, definition, insensitive) {
const matchingTerm = this.termsByLowerText.get(text.toLowerCase());
if (matchingTerm) {
return matchingTerm;
async addTerm(term, definition, insensitive) {
if (typeof term === 'string') {
const matchingTerm = this.termsByLowerText.get(term.toLowerCase());
if (matchingTerm) {
return matchingTerm;
}
term = await this.client.createGlossaryTerm({
text: term,
definition,
insensitive,
});
}
const term = await this.client.createGlossaryTerm({
text,
definition,
insensitive,
});
if (term.insensitive) {

@@ -93,15 +114,17 @@ term.text = term.text.toLowerCase();

async updateTerm(termId, update) {
const term = this.termsById.get(termId);
const term = this.termsById.get(typeof termId === 'string' ? termId : termId.termId);
if (!term) {
throw new Error(`Term ${termId} not found.`);
}
const updated = await this.client.updateGlossaryTerm(termId, {
text: update.text === term.text ? undefined : update.text,
definition: update.definition === term.definition
? undefined
: update.definition || null,
insensitive: typeof update.insensitive === 'boolean'
? update.insensitive
: undefined,
});
const updated = typeof termId === 'string'
? await this.client.updateGlossaryTerm(termId, {
text: update.text === term.text ? undefined : update.text,
definition: update.definition === term.definition
? undefined
: update.definition || null,
insensitive: typeof update.insensitive === 'boolean'
? update.insensitive
: undefined,
})
: termId;
if (updated.insensitive) {

@@ -113,14 +136,12 @@ updated.text = updated.text.toLowerCase();

this.termsById.set(updated.termId, updated);
if (updated.text !== term.text) {
this.removeTermFromDictionary(term);
this.addTermToDictionary(updated);
for (const listener of this.listeners.termRemoved) {
listener(term);
}
for (const listener of this.listeners.newTerm) {
listener(updated);
}
this.removeTermFromDictionary(term);
this.addTermToDictionary(updated);
for (const listener of this.listeners.termRemoved) {
listener(term);
}
for (const listener of this.listeners.newTerm) {
listener(updated);
}
}
async removeTerm(textId) {
async removeTerm(textId, options) {
const term = this.termsById.get(textId);

@@ -130,3 +151,5 @@ if (!term) {

}
await this.client.deleteGlossaryTerm(textId);
if (!options?.localOnly) {
await this.client.deleteGlossaryTerm(textId);
}
this.termsById.delete(textId);

@@ -133,0 +156,0 @@ this.termsByLowerText.delete(term.lower);

@@ -7,3 +7,7 @@ /// <reference types="node" />

*/
export declare function prepareImage(data: Buffer): Promise<Buffer>;
export declare function prepareImage(data: Buffer): Promise<{
data: Buffer;
width: number;
height: number;
}>;
//# sourceMappingURL=image.d.ts.map

@@ -20,7 +20,7 @@ import sharp from 'sharp';

});
return await img.toBuffer();
return { data: await img.toBuffer(), width, height };
}
// otherwise, just return the original data.
return data;
return { data, width, height };
}
//# sourceMappingURL=image.js.map

@@ -5,2 +5,3 @@ export * from './client.js';

export * from './util.js';
export * from './websocketEvents.js';
//# sourceMappingURL=index.d.ts.map

@@ -5,2 +5,3 @@ export * from './client.js';

export * from './util.js';
export * from './websocketEvents.js';
//# sourceMappingURL=index.js.map

@@ -7,2 +7,5 @@ import { z } from 'zod';

latestCommitNumber: z.ZodNumber;
latestTranslationCommitNumber: z.ZodOptional<z.ZodNumber>;
wc: z.ZodDefault<z.ZodNumber>;
latest: z.ZodOptional<z.ZodBoolean>;
closed: z.ZodOptional<z.ZodBoolean>;

@@ -13,2 +16,5 @@ }, "strip", z.ZodTypeAny, {

latestCommitNumber: number;
wc: number;
latestTranslationCommitNumber?: number | undefined;
latest?: boolean | undefined;
closed?: boolean | undefined;

@@ -19,12 +25,18 @@ }, {

branchId?: unknown;
latestTranslationCommitNumber?: number | undefined;
wc?: number | undefined;
latest?: boolean | undefined;
closed?: boolean | undefined;
}>;
export type BranchPatch = z.infer<typeof patchBranchSchema>;
export declare const patchBranchSchema: z.ZodObject<{
export type BranchPatch = z.infer<typeof branchPatchSchema>;
export declare const branchPatchSchema: z.ZodObject<{
closed: z.ZodOptional<z.ZodBoolean>;
latest: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
closed?: boolean | undefined;
latest?: boolean | undefined;
}, {
closed?: boolean | undefined;
latest?: boolean | undefined;
}>;
//# sourceMappingURL=types.branches.d.ts.map

@@ -7,2 +7,10 @@ import { z } from 'zod';

latestCommitNumber: commitNumberSchema.describe("The latest commit's miniversion."),
latestTranslationCommitNumber: commitNumberSchema
.optional()
.describe('The commit miniversion of the most recently uploaded translation.'),
wc: z.number().int().default(0).describe('Word count of the branch.'),
latest: z
.boolean()
.optional()
.describe('If this is the latest non-develop branch. Can only be true for one branch.'),
closed: z

@@ -13,5 +21,6 @@ .boolean()

});
export const patchBranchSchema = z.object({
export const branchPatchSchema = z.object({
closed: z.boolean().optional(),
latest: z.boolean().optional(),
});
//# sourceMappingURL=types.branches.js.map

@@ -6,5 +6,7 @@ export * from './types.annotations.js';

export * from './types.images.js';
export * from './types.issues.js';
export * from './types.lib.js';
export * from './types.projects.js';
export * from './types.strings.js';
export * from './types.users.js';
//# sourceMappingURL=types.d.ts.map

@@ -6,5 +6,7 @@ export * from './types.annotations.js';

export * from './types.images.js';
export * from './types.issues.js';
export * from './types.lib.js';
export * from './types.projects.js';
export * from './types.strings.js';
export * from './types.users.js';
//# sourceMappingURL=types.js.map

@@ -7,2 +7,3 @@ import { z } from 'zod';

export declare const stringSchema: z.ZodEffects<z.ZodString, string, unknown>;
export declare const dateSchema: z.ZodEffects<z.ZodDate, Date, unknown>;
export declare const nullableBoolean: z.ZodEffects<z.ZodOptional<z.ZodBoolean>, boolean | undefined, unknown>;

@@ -9,0 +10,0 @@ export declare const branchIdSchema: z.ZodEffects<z.ZodString, string, unknown>;

import { z } from 'zod';
/** A schema for a non-null string, that gets trimmed prior to validation */
export const stringSchema = z.preprocess((s) => (typeof s === 'string' ? s.trim() : s), z.string().min(1));
export const dateSchema = z.preprocess((val) => {
val = val instanceof Date ? val : new Date(val);
return isNaN(val.getTime()) ? undefined : val;
}, z.date());
export const nullableBoolean = z.preprocess((val) => ([true, false].includes(val) ? val : undefined), z.boolean().optional());

@@ -5,0 +9,0 @@ export const branchIdSchema = stringSchema.describe('A Branch ID, e.g. "develop" or "c101", or, for some cased, special keywords.');

@@ -55,4 +55,4 @@ import { z } from 'zod';

*/
export type CommittedString = z.infer<typeof committedStringSchema>;
export declare const committedStringSchema: z.ZodObject<{
export type StringCommitted = z.infer<typeof stringCommittedSchema>;
export declare const stringCommittedSchema: z.ZodObject<{
projectId: z.ZodString;

@@ -63,2 +63,3 @@ branchId: z.ZodEffects<z.ZodString, string, unknown>;

hash: z.ZodEffects<z.ZodString, string, unknown>;
wc: z.ZodDefault<z.ZodNumber>;
data: z.ZodObject<{

@@ -107,5 +108,7 @@ stringId: z.ZodEffects<z.ZodString, string, unknown>;

}>;
lastChanged: z.ZodOptional<z.ZodEffects<z.ZodDate, Date, unknown>>;
}, "strip", z.ZodTypeAny, {
projectId: string;
branchId: string;
wc: number;
data: {

@@ -129,2 +132,3 @@ stringId: string;

audited?: boolean | undefined;
lastChanged?: Date | undefined;
}, {

@@ -151,3 +155,107 @@ projectId: string;

hash?: unknown;
wc?: number | undefined;
lastChanged?: unknown;
}>;
export type StringLocalized = z.infer<typeof stringLocalizedSchema>;
export declare const stringLocalizedSchema: z.ZodObject<{
projectId: z.ZodString;
branchId: z.ZodEffects<z.ZodString, string, unknown>;
wc: z.ZodDefault<z.ZodNumber>;
data: z.ZodObject<{
stringId: z.ZodEffects<z.ZodString, string, unknown>;
sortKey: z.ZodEffects<z.ZodString, string, unknown>;
text: z.ZodEffects<z.ZodString, string, unknown>;
immutable: z.ZodOptional<z.ZodBoolean>;
maxCharacters: z.ZodOptional<z.ZodNumber>;
pointer: z.ZodOptional<z.ZodEffects<z.ZodString, string, unknown>>;
description: z.ZodOptional<z.ZodEffects<z.ZodString, string, unknown>>;
category: z.ZodOptional<z.ZodEffects<z.ZodString, string, unknown>>;
entity: z.ZodOptional<z.ZodEffects<z.ZodString, string, unknown>>;
property: z.ZodOptional<z.ZodEffects<z.ZodString, string, unknown>>;
images: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodString, string, unknown>, "many">>;
speaker: z.ZodOptional<z.ZodEffects<z.ZodString, string, unknown>>;
speakerId: z.ZodOptional<z.ZodEffects<z.ZodString, string, unknown>>;
}, "strip", z.ZodTypeAny, {
stringId: string;
text: string;
sortKey: string;
immutable?: boolean | undefined;
maxCharacters?: number | undefined;
pointer?: string | undefined;
description?: string | undefined;
category?: string | undefined;
entity?: string | undefined;
property?: string | undefined;
images?: string[] | undefined;
speaker?: string | undefined;
speakerId?: string | undefined;
}, {
stringId?: unknown;
sortKey?: unknown;
text?: unknown;
immutable?: boolean | undefined;
maxCharacters?: number | undefined;
pointer?: unknown;
description?: unknown;
category?: unknown;
entity?: unknown;
property?: unknown;
images?: unknown[] | undefined;
speaker?: unknown;
speakerId?: unknown;
}>;
edit: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodString, string, unknown>>>;
audited: z.ZodOptional<z.ZodBoolean>;
hash: z.ZodEffects<z.ZodString, string, unknown>;
lastChanged: z.ZodOptional<z.ZodEffects<z.ZodDate, Date, unknown>>;
l10n: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodString, string, unknown>>>;
}, "strip", z.ZodTypeAny, {
projectId: string;
branchId: string;
wc: number;
data: {
stringId: string;
text: string;
sortKey: string;
immutable?: boolean | undefined;
maxCharacters?: number | undefined;
pointer?: string | undefined;
description?: string | undefined;
category?: string | undefined;
entity?: string | undefined;
property?: string | undefined;
images?: string[] | undefined;
speaker?: string | undefined;
speakerId?: string | undefined;
};
hash: string;
edit?: string | null | undefined;
audited?: boolean | undefined;
lastChanged?: Date | undefined;
l10n?: Record<string, string> | undefined;
}, {
projectId: string;
data: {
stringId?: unknown;
sortKey?: unknown;
text?: unknown;
immutable?: boolean | undefined;
maxCharacters?: number | undefined;
pointer?: unknown;
description?: unknown;
category?: unknown;
entity?: unknown;
property?: unknown;
images?: unknown[] | undefined;
speaker?: unknown;
speakerId?: unknown;
};
branchId?: unknown;
wc?: number | undefined;
edit?: unknown;
audited?: boolean | undefined;
hash?: unknown;
lastChanged?: unknown;
l10n?: Record<string, unknown> | undefined;
}>;
export type StringsPut = z.infer<typeof stringsPutSchema>;

@@ -241,8 +349,7 @@ export declare const stringsPutSchema: z.ZodObject<{

commitNumber: z.ZodNumber;
translationCommitNumber: z.ZodOptional<z.ZodNumber>;
strings: z.ZodArray<z.ZodObject<{
projectId: z.ZodString;
branchId: z.ZodEffects<z.ZodString, string, unknown>;
edit: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodString, string, unknown>>>;
audited: z.ZodOptional<z.ZodBoolean>;
hash: z.ZodEffects<z.ZodString, string, unknown>;
wc: z.ZodDefault<z.ZodNumber>;
data: z.ZodObject<{

@@ -291,5 +398,11 @@ stringId: z.ZodEffects<z.ZodString, string, unknown>;

}>;
edit: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodString, string, unknown>>>;
audited: z.ZodOptional<z.ZodBoolean>;
hash: z.ZodEffects<z.ZodString, string, unknown>;
lastChanged: z.ZodOptional<z.ZodEffects<z.ZodDate, Date, unknown>>;
l10n: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodString, string, unknown>>>;
}, "strip", z.ZodTypeAny, {
projectId: string;
branchId: string;
wc: number;
data: {

@@ -313,2 +426,4 @@ stringId: string;

audited?: boolean | undefined;
lastChanged?: Date | undefined;
l10n?: Record<string, string> | undefined;
}, {

@@ -332,5 +447,8 @@ projectId: string;

branchId?: unknown;
wc?: number | undefined;
edit?: unknown;
audited?: boolean | undefined;
hash?: unknown;
lastChanged?: unknown;
l10n?: Record<string, unknown> | undefined;
}>, "many">;

@@ -343,2 +461,3 @@ }, "strip", z.ZodTypeAny, {

branchId: string;
wc: number;
data: {

@@ -362,3 +481,6 @@ stringId: string;

audited?: boolean | undefined;
lastChanged?: Date | undefined;
l10n?: Record<string, string> | undefined;
}[];
translationCommitNumber?: number | undefined;
}, {

@@ -384,7 +506,11 @@ commitNumber: number;

branchId?: unknown;
wc?: number | undefined;
edit?: unknown;
audited?: boolean | undefined;
hash?: unknown;
lastChanged?: unknown;
l10n?: Record<string, unknown> | undefined;
}[];
branchId?: unknown;
translationCommitNumber?: number | undefined;
}>;

@@ -391,0 +517,0 @@ export type StringPatch = z.infer<typeof stringPatchSchema>;

import { z } from 'zod';
import { branchIdSchema, commitNumberSchema, projectIdSchema, stringIdSchema, stringSchema, } from './types.lib.js';
import { branchIdSchema, commitNumberSchema, dateSchema, projectIdSchema, stringIdSchema, stringSchema, } from './types.lib.js';
export const sortKeySchema = stringSchema.describe('A string that, when used to sort against other strings, puts this string into a sensible order for loc. It also provides some semantic information about the string, though it may not be particularly human-friendly.');

@@ -43,3 +43,3 @@ export const stringTextSchema = stringSchema.describe('The English version of the string.');

});
export const committedStringSchema = z.object({
export const stringCommittedSchema = z.object({
projectId: projectIdSchema,

@@ -50,4 +50,11 @@ branchId: branchIdSchema,

hash: stringSchema.describe('Hash of the data, to simplify checking for changes.'),
wc: z.number().int().default(0).describe('Word count of the string.'),
data: stringDataSchema.describe("The string's data, including its text, id, etc. This is immutable data sent from the source."),
lastChanged: dateSchema
.optional()
.describe("The last time this string's was changed."),
});
export const stringLocalizedSchema = stringCommittedSchema.extend({
l10n: z.record(stringSchema).optional().describe('Translations.'),
});
export const stringsPutSchema = z.object({

@@ -61,3 +68,4 @@ commitNumber: commitNumberSchema,

commitNumber: commitNumberSchema,
strings: z.array(committedStringSchema),
translationCommitNumber: commitNumberSchema.optional(),
strings: z.array(stringLocalizedSchema),
});

@@ -64,0 +72,0 @@ export const stringPatchSchema = z.object({

@@ -9,2 +9,3 @@ import { z } from 'zod';

canCommit: z.ZodOptional<z.ZodBoolean>;
canTranslate: z.ZodOptional<z.ZodBoolean>;
regeneratePassword: z.ZodOptional<z.ZodBoolean>;

@@ -15,2 +16,3 @@ }, "strip", z.ZodTypeAny, {

canCommit?: boolean | undefined;
canTranslate?: boolean | undefined;
regeneratePassword?: boolean | undefined;

@@ -21,2 +23,3 @@ }, {

canCommit?: boolean | undefined;
canTranslate?: boolean | undefined;
regeneratePassword?: boolean | undefined;

@@ -31,2 +34,3 @@ }>;

canCommit: z.ZodEffects<z.ZodOptional<z.ZodBoolean>, boolean | undefined, unknown>;
canTranslate: z.ZodEffects<z.ZodOptional<z.ZodBoolean>, boolean | undefined, unknown>;
password: z.ZodOptional<z.ZodEffects<z.ZodString, string, unknown>>;

@@ -39,2 +43,3 @@ }, "strip", z.ZodTypeAny, {

canCommit?: boolean | undefined;
canTranslate?: boolean | undefined;
password?: string | undefined;

@@ -47,4 +52,5 @@ }, {

canCommit?: unknown;
canTranslate?: unknown;
password?: unknown;
}>;
//# sourceMappingURL=types.users.d.ts.map

@@ -12,2 +12,3 @@ import { z } from 'zod';

canCommit: z.boolean().optional(),
canTranslate: z.boolean().optional(),
regeneratePassword: z.boolean().optional(),

@@ -21,2 +22,3 @@ });

canCommit: nullableBoolean,
canTranslate: nullableBoolean,
password: stringSchema

@@ -23,0 +25,0 @@ .optional()

@@ -11,2 +11,3 @@ export type AsyncFunction = (...args: any[]) => Promise<any>;

export declare function parseText(text: string): Substring[];
export declare function countWords(text: string): number;
export declare function lowerCompare(a: string, b: string): number;

@@ -50,3 +51,4 @@ export declare function allEqual<T>(arr: T[]): boolean;

export declare function parseCommentText(text: string): CommentToken[];
export declare function normalizeLanguageCode(language: string | undefined): string;
export {};
//# sourceMappingURL=util.d.ts.map

@@ -0,1 +1,2 @@

import { marked } from 'marked';
import { assert } from './errors.js';

@@ -7,3 +8,3 @@ import { usernamePatternString } from './types.users.js';

const variablePattern = /^\{[a-z0-9_]+\}$/;
const textPartsPattern = /(\{[a-z0-9_]+\}|[<>(){}[\]:;|@#,!?+/*="“”\s&-]|['’](?:s|ve|d|ll|re)\b|\.{3}|\.[^A-Za-z]|\.$|\b[\d]+(?:\.\d+)?%?)/u;
const textPartsPattern = /(\{[a-z0-9_]+\}|\d+(?:st|th|rd)|[<>(){}[\]:;|@#,!?+/*="“”\s&-]|['’](?:s|ve|d|ll|re)\b|\.{3}|\.[^A-Za-z]|\.$|\b[\d]+(?:\.\d+)?%?)/u;
export function parseText(text) {

@@ -27,2 +28,5 @@ const substrings = [];

}
export function countWords(text) {
return parseText(text).filter((s) => s.isWord).length;
}
export function lowerCompare(a, b) {

@@ -120,2 +124,3 @@ return a.toLowerCase().localeCompare(b.toLowerCase());

export function parseCommentText(text) {
text = marked.parse(text);
const split = text.split(new RegExp(`(@${usernamePatternString})`, 'g'));

@@ -140,2 +145,11 @@ const parsed = [];

}
export function normalizeLanguageCode(language) {
assert(typeof language === 'string', 'Language code not provided.');
let [languageCode, countryCode] = language.split('-');
language =
languageCode.toLowerCase() +
(countryCode ? '-' + countryCode.toUpperCase() : '');
assert(language.match(/^[a-z]{2}(-[A-Z]{2,3})?$/), `Target language must be a valid BCP 47 language tag, but got: ${language}`);
return language;
}
//# sourceMappingURL=util.js.map
{
"name": "@bscotch/cl2-string-server-shared",
"version": "0.5.2",
"version": "0.6.0",
"description": "",

@@ -29,3 +29,3 @@ "keywords": [],

"dependencies": {
"marked": "11.1.1",
"marked": "12.0.0",
"nspell": "2.1.5",

@@ -37,3 +37,4 @@ "sharp": "0.33.2",

"@types/nspell": "2.1.6",
"source-map-support": "0.5.21"
"source-map-support": "0.5.21",
"typescript": "^5.4.0-beta"
},

@@ -40,0 +41,0 @@ "publishConfig": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc