# @uipath/packager-tool-datafabric

The Data Fabric entity library for the solution packager and its hosts: the
schema, validation, resource-file I/O and scaffolding for **Entity projects**
(`.entity` files paired with entity definition resources under
`resources/solution_folder/entity/native/`).

Owned by Data Fabric. Consumed by `@uipath/data-fabric-tool` (packing via
`uip solution pack`) and the Maestro VS Code extension (editing, scaffolding,
in-process pack).

## Two entries, on purpose

| Entry | Import | Safe where | Contains |
|---|---|---|---|
| Root | `@uipath/packager-tool-datafabric` | Everywhere (browser bundles included) | Types, schema, validators, resource read/write. **Side-effect-free:** importing defines things only — no registration, no disk, no network. |
| Init | `@uipath/packager-tool-datafabric/init` | Node only | `entityInitAsync` — scaffolding. Pulls `@uipath/filesystem` + `@uipath/solution-sdk`, which must never enter browser bundles. |

Rule of thumb: if you only need to *understand* entities, import the root; if
you need to *create* an entity project on disk, import `/init`.

## Module map

```text
src/
├── schema/
│   ├── entity-json.ts            # EntityJSON/EntityField types (PascalCase — the wire),
│   │                             #   SqlTypeName + FieldDisplayType value sets,
│   │                             #   NAME_PATTERN, GA type allowlist (F5, closed)
│   ├── create-entity-skeleton.ts # new entity = 5 canonical system fields + minted GUIDs
│   └── validate-entity.ts        # every schema rule, one implementation (editor + pack)
├── resource/
│   ├── unified-resource-file.ts  # resource wrapper types + entityResourcePath()
│   └── resource-io.ts            # wrapEntityJson · unwrapResource · updateResourceSchema ·
│                                 #   serialize (deterministic: 2-space, LF, trailing \n)
├── init/
│   └── entity-init-service.ts    # entityInitAsync (project.uiproj + stub + resource +
│                                 #   .uipx registration; throws + rolls back)
├── index.ts                      # root barrel (browser-safe)
└── init.ts                       # /init entry (node-only)
tests/fixtures/                   # Order stub, plain EntityJSON, wrapped resource, Studio Web sample
                                  #   (PurchaseOrder.resource.json is byte-pinned by a test)
tests/                            # *.spec.ts (pure) + *.integration.test.ts (real fs)
```

## Commands

From the repo root (workspace toolchain):

```bash
bun install                                                        # once
bunx vitest run --project node packages/packager/packager-tool-datafabric/
```

From this package directory:

```bash
bun run test            # vitest run — unit specs + the init integration test
bun run test:coverage
bun run build           # browser root bundle + node init bundle + .d.ts
bun run lint            # biome
```

Notes:

- `tests/*.spec.ts` are pure (no workspace deps) — they run anywhere vitest
  and typescript are available.
- `tests/entity-init-service.integration.test.ts` exercises the real
  filesystem and the real `@uipath/solution-sdk` registration pipeline
  (mirroring `flow-tool`'s init spec), so it needs the workspace install.

## Where the schema truth comes from

`EntityJSON` is the **authoring/deploy document** (PascalCase, name-based
`ReferenceEntity { Name }` references) — the format Data Fabric's exporter
writes and its deploy deserializes. It is deliberately NOT imported from
`@uipath/data.service.typescript.client`, which models the external REST API
(camelCase, GUID references, server-side fields). The enum **value sets**
(`SqlTypeName`, `FieldDisplayType`) are seeded from that client with
provenance comments; the GA type allowlist is confirmed against DF's own field
creation (`transformType()` in CommonEntityPlatform's client,
`CreateFileFieldForImport` on the backend).

**Changing the entity schema?** The source of truth is CommonEntityPlatform's
export model. If you change it there, update `src/schema/entity-json.ts`, the
`tests/fixtures/`, and the validator here in the same breath — and keep the
`tests/fixtures/Order.*` files in sync with CEP's golden-fixture check.
