Skip to content

Commit

Permalink
Bootstrap js-commons package (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
evshi authored Nov 5, 2024
1 parent db0cb5e commit 59be854
Show file tree
Hide file tree
Showing 14 changed files with 458 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/twelve-cougars-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"eslint-config-custom": patch
"@ensembleui/js-commons": patch
---

Add js-commons package
3 changes: 1 addition & 2 deletions packages/eslint-config-custom/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ module.exports = {
extends: [
"@vercel/style-guide/eslint/node",
"@vercel/style-guide/eslint/typescript",
"plugin:prettier/recommended"
].map(require.resolve),
].map(require.resolve).concat("plugin:prettier/recommended"),
plugins: ["prettier"],
parserOptions: {
project,
Expand Down
4 changes: 4 additions & 0 deletions packages/js-commons/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
extends: ["custom/library"],
ignorePatterns: ["tsup.config.ts"],
};
1 change: 1 addition & 0 deletions packages/js-commons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# `js-commons`
9 changes: 9 additions & 0 deletions packages/js-commons/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-env node */
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "jsdom",
moduleNameMapper: {
"^lodash-es$": "lodash",
},
};
31 changes: 31 additions & 0 deletions packages/js-commons/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@ensembleui/js-commons",
"version": "0.0.1",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"./dist/**"
],
"repository": "https://github.com/EnsembleUI/ensemble-react",
"scripts": {
"dev": "tsup --watch",
"build": "tsup",
"test": "jest --passWithNoTests",
"lint": "eslint ."
},
"lint-staged": {
"*.{ts,tsx}": "eslint --fix"
},
"peerDependencies": {
"firebase": "9.10.0"
},
"devDependencies": {
"@types/lodash-es": "^4.17.8",
"dayjs": "^1.11.10",
"eslint-config-custom": "workspace:*",
"firebase": "9.10.0",
"lodash-es": "^4.17.21",
"tsconfig": "workspace:*",
"tsup": "^7.2.0"
}
}
142 changes: 142 additions & 0 deletions packages/js-commons/src/dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/**
* DTOs = Data Transfer Objects
*
* Mostly equivalent to raw JSON definition over wire
*/
export interface EnsembleDocument {
readonly id: string;
readonly name: string;
readonly content: string;
readonly type: EnsembleDocumentType;

readonly description?: string;
readonly isRoot?: boolean;
readonly isDraft?: boolean;
readonly isArchived?: boolean;
readonly updatedAt?: Date;
readonly updatedBy?: {
name: string;
};
}

export enum EnsembleDocumentType {
I18n = "i18n",
Theme = "theme",
Asset = "asset",
Screen = "screen",
Font = "font",
Widget = "internal_widget",
Script = "internal_script",
Environment = "config",
Secrets = "secrets",
Label = "label",
}

export interface ApplicationDTO
extends Omit<EnsembleDocument, "content" | "type"> {
readonly description?: string;
readonly isPublic?: boolean;
readonly isAutoGenerated?: boolean;
readonly isReact?: boolean;
readonly status?: string;
readonly category?: AppCategory;
readonly collaborators?: Map<string, AccessType>;
readonly demoOrder?: number;
readonly publishingHistory?: PublishingHistory[];
readonly groupLabels?: Map<string, string>;

readonly manifest?: Record<
string,
Partial<EnsembleDocument> & {
filePath?: string;
}
>;

readonly screens: ScreenDTO[];
readonly widgets: WidgetDTO[];
readonly scripts: ScriptDTO[];
readonly theme?: ThemeDTO;
readonly themes?: ThemeDTO[];
readonly languages?: LanguageDTO[];
readonly assets?: AssetDTO[];
readonly env?: EnvironmentDTO;
}

export interface HasLabel {
readonly labelGroup?: Label;
}

export interface Label {
readonly id: string;
readonly name: string;
}

export interface PublishingHistory {
readonly publishedTo: string;
readonly createdAt: Date;
readonly publishedBy: string;
readonly publishingLog: string;
readonly role: string;
}

export type EnsembleLabeledDocument = EnsembleDocument & HasLabel;

export type ScreenDTO = EnsembleLabeledDocument & {
readonly type: EnsembleDocumentType.Screen;

readonly path?: string;
// deprecated?
readonly category?: string;
};

export type WidgetDTO = EnsembleLabeledDocument & {
readonly type: EnsembleDocumentType.Widget;
};

export type ScriptDTO = EnsembleLabeledDocument & {
readonly type: EnsembleDocumentType.Script;
};
export type ThemeDTO = EnsembleDocument & {
readonly type: EnsembleDocumentType.Theme;
};

export type LanguageDTO = EnsembleDocument & {
readonly defaultLocale: boolean;
};

export interface EnvironmentDTO {
readonly envVariables?: Record<string, unknown>;
readonly secretVariables?: Record<string, unknown>;
}

export type AssetDTO = EnsembleDocument & {
readonly type: EnsembleDocumentType.Asset;
readonly fileName: string;
readonly publicUrl: string;
readonly copyText: string;
};

export type FontDTO = EnsembleDocument & {
readonly name?: string;
readonly fontFamily: string;
readonly fontWeight: string;
readonly fontStyle: string;
readonly fontType: string;
readonly publicUrl?: string;
};

export enum AppCategory {
Demo = "Demo",
Template = "Template",
}

export enum AccessType {
Read = "read",
Write = "write",
Owner = "owner",
}

export type EnsembleDocumentHistoryItem = EnsembleDocument & {
readonly comment: string;
readonly label: string;
};
Loading

0 comments on commit 59be854

Please sign in to comment.